Files
mesh-delivery/modules/mesh-delivery-assigner/internal/assigngraph/revert_test.go
T

50 lines
2.1 KiB
Go

package assigngraph
import (
"context"
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
)
// Design 47 G §298, §300, A-217 (AS17): a want is a revert when the module had its fingerprint in an earlier assignment graph revision than
// the one it now runs from; a kept data whose form changed is read from the entries' manifests.
func TestAWantGoingBackToAnEarlierFingerprintIsARevert(t *testing.T) {
ctx := context.Background()
o := memObjects{}
at := time.Now()
for _, fp := range []string{"src2:a", "src2:b", "src2:c"} {
in := Inputs{Halves: map[string]meshcatalogclient.Half{"main": half("main", 1, meshcatalog.CatalogEntry{Module: "web", Fp: fp})},
Placements: map[string]mma.Assignments{"ace": {Node: "ace", Modules: []mma.PlacedModule{{Module: "web"}}}}, FirstBranch: func(string) string { return "main" }}
if _, _, err := Keep(ctx, o, Compute(in), "test", at); err != nil {
t.Fatal(err)
}
}
for _, c := range []struct {
run, want string
revert bool
}{{"src2:c", "src2:a", true}, {"src2:c", "src2:b", true}, {"src2:a", "src2:c", false}, {"src2:b", "src2:b", false}, {"src2:c", "src2:zz", false}} {
if got, err := Reverted(ctx, o, "ace", "web", c.run, c.want); err != nil || got != c.revert {
t.Errorf("runs %s, wanted %s: revert %v %v, want %v", c.run, c.want, got, err, c.revert)
}
}
}
func TestAKeptDatasFormIsReadFromTheEntrysManifest(t *testing.T) {
entry := func(form int) meshcatalog.CatalogEntry {
return meshcatalog.CatalogEntry{Module: "web", Manifest: map[string]any{"module": "web",
"state": []any{map[string]any{"name": "sessions", "form": form}}}}
}
same, err := FormChanges(entry(1), entry(1))
if err != nil || len(same) != 0 {
t.Fatalf("same form: %v %v", same, err)
}
got, err := FormChanges(entry(1), entry(2))
if err != nil || len(got) != 1 || got[0].Name != "sessions" {
t.Errorf("changed form: %+v %v", got, err)
}
}