Files
mesh-catalog/modules/mesh-build-go/cmd/mesh-build-go/needtools_test.go
T

52 lines
2.0 KiB
Go

package main
import (
"slices"
"strings"
"testing"
sdkstep "git.novox.be/novox/mesh-delivery/sdk/buildstep"
)
// Issue 1309: a test that runs a step in bubblewrap is proof only where it runs. Where a build module judges (it hands
// the tests MESH_BUILD_NODE=1) a missing bubblewrap is a failure, since every build node declares and has it; a missing
// bubblewrap anywhere else, or any other missing tool, is a skip that says NOT RUN.
func TestAMissingToolSkipsExceptBubblewrapOnABuildNode(t *testing.T) {
for _, c := range []struct {
name string
tool string
onBuildNode bool
want string
}{
{"bubblewrap on a desk", "bwrap", false, "skip"},
{"bubblewrap on a build node", "bwrap", true, "fail"},
{"another tool on a build node", "initdb", true, "skip"},
{"another tool on a desk", "initdb", false, "skip"},
} {
if got := missingToolAction(c.tool, c.onBuildNode); got != c.want {
t.Errorf("%s: %q, want %q", c.name, got, c.want)
}
}
}
// The levels a build module judges hand the tests the build node mark, with the siblings they read.
func TestEveryLevelHandsTheTestsTheBuildNodeMark(t *testing.T) {
m := &Module{Work: t.TempDir()}
if env := m.checkEnv("ws1", nil); !slices.Contains(env, BuildNodeEnv+"=1") || slices.ContainsFunc(env, func(e string) bool { return strings.HasPrefix(e, sdkstep.NodeNamesEnv) }) {
t.Errorf("env %v lacks %s=1, or names nodes when none were asked", env, BuildNodeEnv)
}
// And the mesh's node names, when the ask carried them (ADR 0567 §12).
if env := m.checkEnv("ws1", []string{"a", "b"}); !slices.Contains(env, sdkstep.NodeNamesEnv+"=a,b") {
t.Errorf("env %v lacks the node names", env)
}
}
// missingToolAction is what a test does when tool is not installed: "fail" for bubblewrap where the build module that
// judges says so (BuildNodeEnv), otherwise "skip".
func missingToolAction(tool string, onBuildNode bool) string {
if tool == "bwrap" && onBuildNode {
return "fail"
}
return "skip"
}