package release import "testing" func TestEmptyColumnIsToday(t *testing.T) { u, err := ParseUpdateSettings("") if err != nil || u.Updates != UpdatesAuto || u.Major != nil || u.Pin != "" || u.InstallRequest != 0 { t.Fatalf("ParseUpdateSettings(\"\") = %+v, %v; want auto and nothing else", u, err) } if !u.Default() { t.Fatal("the empty column is not the default") } } func TestColumnRoundTrips(t *testing.T) { two := 2 u := UpdateSettings{Updates: UpdatesManual, Channel: "stable", Major: &two, Pin: "v9", InstallRequest: 4, InstallFastTrack: true, Control: []string{ControlUpdates, ControlPin}} got, err := ParseUpdateSettings(u.Column()) if err != nil || got.Column() != u.Column() || *got.Major != 2 { t.Fatalf("round trip = %+v, %v", got, err) } if u.Default() { t.Fatal("manual is not the default") } } func TestDefaultIgnoresChannelAndControl(t *testing.T) { u := UpdateSettings{Updates: UpdatesAuto, Channel: "beta", Control: []string{ControlUpdates}} if !u.Default() { t.Fatal("auto with no major, pin or request is today's behaviour whatever the channel") } } func TestParseRefusesNonsense(t *testing.T) { for _, col := range []string{`{`, `{"updates":"sometimes"}`, `{"updates":"auto","major":-1}`, `{"updates":"auto","pin":"../x"}`} { if _, err := ParseUpdateSettings(col); err == nil { t.Errorf("%s was accepted", col) } } } func TestValidControl(t *testing.T) { if !ValidControl(nil) || !ValidControl([]string{"updates", "pin"}) || ValidControl([]string{"updates", "updates"}) || ValidControl([]string{"bake"}) { t.Fatal("ValidControl is wrong") } }