Files
mesh-catalog/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/ended_test.go
T

59 lines
2.3 KiB
Go

package main
import (
"encoding/json"
"fmt"
"testing"
"time"
)
// Issue 1098: a value of the assignments bucket with `ended` set takes the module off the node exactly as a removed
// key does, and a value with the fields the controller adds to an assignment (build, commit, rollout, unknown ones)
// is read under the same key.
func TestNatsAnEndedAssignmentTakesAModuleOffTheNodeLikeARemovedKey(t *testing.T) {
b := startBus(t)
heard := b.listen(t)
e := startEngine(t, map[string]string{dunstrc: "owned"})
b.config(t, "dunst", "font-size", "13")
p := dunst(t)
b.assign(t, "dunst", p)
aClient(t, b, e, t.TempDir(), time.Hour)
eventually(t, "the needs are recorded", func() bool { return len(b.keys(t, NeedsBucket, node+".dunst.")) == 2 })
b.put(t, AssignmentsBucket, node+".dunst", fmt.Sprintf(`{"node":%q,"module":"dunst","assigned":"2026-10-14T20:00:00Z",`+
`"build":"b-1","commit":"abc","rollout":"r-1","ended":"2026-10-18T01:00:00Z",`+
`"provisioning":%s}`, node, planJSON(t, p)))
eventually(t, "its needs go", func() bool { return len(b.keys(t, NeedsBucket, node+".dunst.")) == 0 })
eventually(t, "its report goes", func() bool { return len(b.keys(t, AppliedBucket, node+".dunst")) == 0 })
eventually(t, "prov.applied says it is removed", func() bool {
r, _ := heard.last("dunst")
return r.Status == StatusRemoved
})
}
func TestNatsAnAssignmentWithTheNewFieldsIsFilledUnderTheSameKey(t *testing.T) {
b := startBus(t)
e := startEngine(t, map[string]string{dunstrc: "owned"})
b.config(t, "dunst", "font-size", "13")
p := dunst(t)
b.assign(t, "dunst", p)
aClient(t, b, e, t.TempDir(), time.Hour)
eventually(t, "the needs are recorded", func() bool { return len(b.keys(t, NeedsBucket, node+".dunst.")) == 2 })
b.put(t, AssignmentsBucket, node+".dunst", fmt.Sprintf(`{"node":%q,"module":"dunst","assigned":"2026-10-14T20:00:00Z",`+
`"build":"b-1","artifact":{"name":"dunst","version":"1"},"commit":"abc","rollout":"r-1",`+
`"since":"2026-10-18T00:00:00Z","ended":"","state":"","future":1,"provisioning":%s}`, node, planJSON(t, p)))
time.Sleep(300 * time.Millisecond)
if got := b.keys(t, NeedsBucket, node+".dunst."); len(got) != 2 {
t.Errorf("a value with the new fields took the module's needs away: %v", got)
}
}
func planJSON(t *testing.T, p Plan) []byte {
t.Helper()
raw, err := json.Marshal(p)
if err != nil {
t.Fatal(err)
}
return raw
}