mirror of https://github.com/tailscale/tailscale/
cmd/tailscale/cli: make 'tailscale update' support Debian/Ubuntu apt
Updates #6995 Change-Id: I3355435db583755e0fc73d76347f6423b8939dfb Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/7029/head
parent
4471e403aa
commit
5ca22a0068
@ -0,0 +1,76 @@
|
|||||||
|
// Copyright (c) 2023 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestUpdateDebianAptSourcesListBytes(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
toTrack string
|
||||||
|
in string
|
||||||
|
want string // empty means want no change
|
||||||
|
wantErr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "stable-to-unstable",
|
||||||
|
toTrack: "unstable",
|
||||||
|
in: "# Tailscale packages for debian buster\ndeb https://pkgs.tailscale.com/stable/debian bullseye main\n",
|
||||||
|
want: "# Tailscale packages for debian buster\ndeb https://pkgs.tailscale.com/unstable/debian bullseye main\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "stable-unchanged",
|
||||||
|
toTrack: "stable",
|
||||||
|
in: "# Tailscale packages for debian buster\ndeb https://pkgs.tailscale.com/stable/debian bullseye main\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "if-both-stable-and-unstable-dont-change",
|
||||||
|
toTrack: "stable",
|
||||||
|
in: "# Tailscale packages for debian buster\n" +
|
||||||
|
"deb https://pkgs.tailscale.com/stable/debian bullseye main\n" +
|
||||||
|
"deb https://pkgs.tailscale.com/unstable/debian bullseye main\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "if-both-stable-and-unstable-dont-change-unstable",
|
||||||
|
toTrack: "unstable",
|
||||||
|
in: "# Tailscale packages for debian buster\n" +
|
||||||
|
"deb https://pkgs.tailscale.com/stable/debian bullseye main\n" +
|
||||||
|
"deb https://pkgs.tailscale.com/unstable/debian bullseye main\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "signed-by-form",
|
||||||
|
toTrack: "unstable",
|
||||||
|
in: "# Tailscale packages for ubuntu jammy\ndeb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/stable/ubuntu jammy main\n",
|
||||||
|
want: "# Tailscale packages for ubuntu jammy\ndeb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/unstable/ubuntu jammy main\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unsupported-lines",
|
||||||
|
toTrack: "unstable",
|
||||||
|
in: "# Tailscale packages for ubuntu jammy\ndeb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/foobar/ubuntu jammy main\n",
|
||||||
|
wantErr: "unexpected/unsupported /etc/apt/sources.list.d/tailscale.list contents",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
newContent, err := updateDebianAptSourcesListBytes([]byte(tt.in), tt.toTrack)
|
||||||
|
if err != nil {
|
||||||
|
if err.Error() != tt.wantErr {
|
||||||
|
t.Fatalf("error = %v; want %q", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tt.wantErr != "" {
|
||||||
|
t.Fatalf("got no error; want %q", tt.wantErr)
|
||||||
|
}
|
||||||
|
var gotChange string
|
||||||
|
if string(newContent) != tt.in {
|
||||||
|
gotChange = string(newContent)
|
||||||
|
}
|
||||||
|
if gotChange != tt.want {
|
||||||
|
t.Errorf("wrong result\n got: %q\nwant: %q", gotChange, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue