51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
//go:build integration
|
|
|
|
package inventory
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAWalksStartIsKeptAndARefusedSaveLeavesItUnsaid(t *testing.T) {
|
|
inv := ForTest(t)
|
|
ctx := t.Context()
|
|
cut := time.Now().UTC().Add(-time.Minute)
|
|
p := Plan{ID: "plan-308", Repository: "novox/mesh-catalog", Commit: "abc", Created: cut, State: PlanBuilding,
|
|
Tiers: [][]string{{"messenger"}}, Modules: map[string]*PlanModule{"messenger": {}},
|
|
Times: &PlanTimes{Cut: &cut, Class: ClassLeaf}}
|
|
var said []string
|
|
was := PlanSaved
|
|
PlanSaved = func(_ *Inventory, p Plan) { said = append(said, p.WalkSaid) }
|
|
t.Cleanup(func() { PlanSaved = was })
|
|
if err := inv.SavePlan(ctx, &p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
back, err := inv.PlanByID(ctx, p.ID)
|
|
if err != nil || back.Times == nil || back.Times.Started == nil || back.Times.Class != ClassLeaf {
|
|
t.Fatalf("the start is kept with the walk: %v %+v", err, back.Times)
|
|
}
|
|
// Read back by another controller and saved: not said again.
|
|
back.State = PlanRolling
|
|
if err := inv.SavePlan(ctx, &back); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// A stale copy ending it is refused, and unmarked.
|
|
stale := p
|
|
stale.Revision = 1
|
|
stale.State = PlanDone
|
|
if err := inv.SavePlan(ctx, &stale); err == nil {
|
|
t.Fatal("a stale save is refused")
|
|
}
|
|
if stale.WalkSaid != "" || stale.Times.Ended != nil {
|
|
t.Fatalf("a refused save is unmarked: %q %+v", stale.WalkSaid, stale.Times)
|
|
}
|
|
back.State = PlanDone
|
|
if err := inv.SavePlan(ctx, &back); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(said) != 3 || said[0] != WalkStarted || said[1] != "" || said[2] != WalkEnded {
|
|
t.Fatalf("said: %q, want started, nothing, ended", said)
|
|
}
|
|
}
|