package buildrun import ( "reflect" "testing" "git.novox.be/novox/mesh-delivery/sdk/buildstep" ) func tc(language, version, digest string) buildstep.Toolchain { return buildstep.Toolchain{Language: language, Version: version, Recipe: "1", Digest: digest} } func TestToolchainSetKeepsEachNodesEntryByLanguageAndSaysWhenOneChanged(t *testing.T) { // 1607/AC6, design 47 G §604 var s ToolchainSet if !s.Set("novox", tc("go", "go1.27.1", "sha256:a")) { t.Error("a first entry did not count as a change") } if s.Set("novox", tc("go", "go1.27.1", "sha256:a")) { t.Error("the same entry again counted as a change") } if !s.Set("novox", tc("go", "go1.27.1", "sha256:b")) { t.Error("a new digest at one version did not count as a change") } s.Set("ace", tc("go", "go1.27.1", "sha256:b")) s.Set("ace", tc("typescript", "tsc5", "")) if got := s.Entries("go"); len(got) != 2 { t.Errorf("go entries = %+v, want two", got) } if got := s.Entries("typescript"); len(got) != 1 || got[0].Node != "ace" || got[0].Version != "tsc5" { t.Errorf("typescript entries = %+v", got) } if !s.Delete("ace", "go") || len(s.Entries("go")) != 1 || s.Delete("ace", "go") { t.Error("a delete did not remove the node's entry once") } } // Design 47 G §472, §574: the digests are those the nodes reporting the agreed version report, sorted, with their nodes. func TestDigestsOfTheAgreedVersion(t *testing.T) { entries := []buildstep.NodeToolchain{ {Node: "novox", Toolchain: tc("go", "1.26.0", "sha256:b")}, {Node: "ace", Toolchain: tc("go", "1.26.0", "sha256:a")}, {Node: "g14", Toolchain: tc("go", "1.26.0", "sha256:a")}, {Node: "shanks", Toolchain: tc("go", "1.25.0", "sha256:c")}, {Node: "old", Toolchain: tc("go", "1.26.0", "")}} got := Digests(entries, tc("go", "1.26.0", "")) want := []AgreedDigest{{Digest: "sha256:a", Nodes: []string{"ace", "g14"}}, {Digest: "sha256:b", Nodes: []string{"novox"}}} if !reflect.DeepEqual(got, want) { t.Errorf("digests = %+v, want %+v", got, want) } }