package manager_test import ( "testing" "slackerbot/internal/model" "slackerbot/internal/testutil" "slackerbot/internal/testutil/clustertest" ) func TestRestartAppliesUpdate(t *testing.T) { c := clustertest.New(t) c.AddOwner(t, testutil.HomeData(), true) u := c.Store.Owner("C1") if c.Mgr.Outdated(c.Ctx, u) { t.Fatal("a container on the current system isn't outdated") } c.Master.Mu.Lock() c.Master.Outdated["c-c1"] = true c.Master.Mu.Unlock() if !c.Mgr.Outdated(c.Ctx, u) { t.Fatal("the node said the container is outdated") } if _, err := c.Mgr.Restart(c.Ctx, "C1", model.OwnerChannel, nil); err != nil { t.Fatal(err) } if !c.Master.IsRunning("c-c1") || c.Mgr.Outdated(c.Ctx, u) { t.Fatal("after a restart the container should run the current system") } if c.Master.Last.Machine != "c-c1" { t.Fatal("the container wasn't started again") } } func TestOutdatedThroughSlave(t *testing.T) { c := clustertest.New(t) u := &model.Owner{ID: "C2", Kind: model.OwnerChannel, Machine: "c-c2", Node: "slave-1", Drive: "/d"} c.Slave.Mu.Lock() c.Slave.Runs["c-c2"], c.Slave.Outdated["c-c2"] = true, true c.Slave.Mu.Unlock() testutil.WaitFor(t, "slave to report the outdated container", func() bool { return c.Mgr.Outdated(c.Ctx, u) }) } func TestRestartStoppedContainerJustStarts(t *testing.T) { c := clustertest.New(t) c.AddOwner(t, testutil.HomeData(), false) if _, err := c.Mgr.Restart(c.Ctx, "C1", model.OwnerChannel, nil); err != nil { t.Fatal(err) } if !c.Master.IsRunning("c-c1") { t.Fatal("a stopped container should just start") } }