| 1 | package release |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestEmptyColumnIsToday(t *testing.T) { |
| 6 | u, err := ParseUpdateSettings("") |
| 7 | if err != nil || u.Updates != UpdatesAuto || u.Major != nil || u.Pin != "" || u.InstallRequest != 0 { |
| 8 | t.Fatalf("ParseUpdateSettings(\"\") = %+v, %v; want auto and nothing else", u, err) |
| 9 | } |
| 10 | if !u.Default() { |
| 11 | t.Fatal("the empty column is not the default") |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | func TestColumnRoundTrips(t *testing.T) { |
| 16 | two := 2 |
| 17 | u := UpdateSettings{Updates: UpdatesManual, Channel: "stable", Major: &two, Pin: "v9", |
| 18 | InstallRequest: 4, InstallFastTrack: true, Control: []string{ControlUpdates, ControlPin}} |
| 19 | got, err := ParseUpdateSettings(u.Column()) |
| 20 | if err != nil || got.Column() != u.Column() || *got.Major != 2 { |
| 21 | t.Fatalf("round trip = %+v, %v", got, err) |
| 22 | } |
| 23 | if u.Default() { |
| 24 | t.Fatal("manual is not the default") |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestDefaultIgnoresChannelAndControl(t *testing.T) { |
| 29 | u := UpdateSettings{Updates: UpdatesAuto, Channel: "beta", Control: []string{ControlUpdates}} |
| 30 | if !u.Default() { |
| 31 | t.Fatal("auto with no major, pin or request is today's behaviour whatever the channel") |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func TestParseRefusesNonsense(t *testing.T) { |
| 36 | for _, col := range []string{`{`, `{"updates":"sometimes"}`, `{"updates":"auto","major":-1}`, `{"updates":"auto","pin":"../x"}`} { |
| 37 | if _, err := ParseUpdateSettings(col); err == nil { |
| 38 | t.Errorf("%s was accepted", col) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestValidControl(t *testing.T) { |
| 44 | if !ValidControl(nil) || !ValidControl([]string{"updates", "pin"}) || ValidControl([]string{"updates", "updates"}) || ValidControl([]string{"bake"}) { |
| 45 | t.Fatal("ValidControl is wrong") |
| 46 | } |
| 47 | } |
| 48 | |