Files
mesh-delivery/modules/mesh-delivery-builder/buildrun/toolchains_test.go
T
jschoubben 71a35a6376 MV1: move contracts and sdk under modules/, importers follow
The delivery repository's contracts and SDK live under modules/ as
mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths
renamed to match the folders (the TypeScript names already did), and
every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools
and mesh-sdk follows in the same group: a design as it should be, one
path per module, checked by the group's check building every importer.

Builds: design 47 G §427, §88

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:09:56 +01:00

50 lines
2.0 KiB
Go

package buildrun
import (
"reflect"
"testing"
"git.novox.be/novox/mesh-delivery/modules/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)
}
}