65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// 1560 (ADR 0476 §1): every environment a step gives its go commands names the recipe's release as the toolchain
|
|
// and never GOTOOLCHAIN=local, which would run the distribution's build.
|
|
func TestEveryStepEnvironmentCarriesTheRecipesRelease(t *testing.T) {
|
|
m := &Module{Cache: t.TempDir()}
|
|
vend := t.TempDir()
|
|
os.MkdirAll(filepath.Join(vend, "vendor"), 0o755)
|
|
os.WriteFile(filepath.Join(vend, "vendor", "modules.txt"), nil, 0o644)
|
|
plain := t.TempDir()
|
|
envs := map[string][]string{
|
|
"goEnv": m.goEnv(), "goEnvFor(plain)": m.goEnvFor(plain), "goEnvFor(vendor)": m.goEnvFor(vend),
|
|
"buildEnv(plain)": m.buildEnv(plain), "buildEnv(vendor)": m.buildEnv(vend),
|
|
}
|
|
for name, env := range envs {
|
|
joined := "\n" + strings.Join(env, "\n") + "\n"
|
|
if !strings.Contains(joined, "\nGOTOOLCHAIN="+RecipeGo+"\n") {
|
|
t.Errorf("%s lacks GOTOOLCHAIN=%s:\n%s", name, RecipeGo, joined)
|
|
}
|
|
if strings.Contains(joined, "GOTOOLCHAIN=local") {
|
|
t.Errorf("%s still says GOTOOLCHAIN=local:\n%s", name, joined)
|
|
}
|
|
if !strings.Contains(joined, "\nGOMODCACHE="+filepath.Join(m.Cache, "gomod")+"\n") {
|
|
t.Errorf("%s lacks the module cache:\n%s", name, joined)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1560 (ADR 0476 §3): the fetch step downloads the change's locked dependencies and nothing else: no `go version`
|
|
// and no toolchain download among its commands, and each go command carries the recipe's release.
|
|
func TestTheFetchStepsCommandsFetchNoToolchain(t *testing.T) {
|
|
f := &fakeStep{gomods: "go.mod\n"}
|
|
m, states := fetchModule(t, f)
|
|
if _, err := fetchTool(t, m)(fetchArgs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st := states.waitEnd(t); st.State != delivery.StepPassed {
|
|
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
|
|
}
|
|
goCalls := 0
|
|
for _, c := range f.calls {
|
|
if strings.Contains(c.line, "version") || strings.Contains(c.line, "toolchain") {
|
|
t.Errorf("the fetch step ran %q", c.line)
|
|
}
|
|
if strings.HasPrefix(c.line, "go ") {
|
|
goCalls++
|
|
if env := strings.Join(c.env, " "); !strings.Contains(env, "GOTOOLCHAIN="+RecipeGo) || strings.Contains(env, "GOTOOLCHAIN=local") {
|
|
t.Errorf("%s: environment %s", c.line, env)
|
|
}
|
|
}
|
|
}
|
|
if goCalls == 0 {
|
|
t.Error("no go command ran")
|
|
}
|
|
}
|