80 lines
2.9 KiB
Go
80 lines
2.9 KiB
Go
package build
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
|
"git.novox.be/novox/mesh-delivery/sdk/buildstep"
|
|
)
|
|
|
|
// ADR 0593 §2 (F3): the imports a Go build module answers at a build's end reach the done key and the log's end entry,
|
|
// where the indexer keeps them on the module.
|
|
func importsABuildAnswersReachTheDoneKeyAndTheLog(t *testing.T) {
|
|
r := newRig(t, goBundle)
|
|
imports := []string{"git.novox.be/novox/mesh-sdk/go", "git.novox.be/novox/mesh-sdk/go/announce"}
|
|
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
|
|
step := r.answer(a)
|
|
var answer map[string]any
|
|
if err := json.Unmarshal(step.Result, &answer); err == nil && a.Language == "go" {
|
|
answer["imports"] = imports
|
|
step.Result, _ = json.Marshal(answer)
|
|
}
|
|
return step
|
|
}
|
|
var logged []builds.BuildLogEntry
|
|
var mu sync.Mutex
|
|
r.b.Node, r.b.Log = "novox", func(e builds.BuildLogEntry) { mu.Lock(); logged = append(logged, e); mu.Unlock() }
|
|
v := r.consider(t, "modules/m")
|
|
if v.State != builds.BuildDone || strings.Join(v.Imports, ",") != strings.Join(imports, ",") {
|
|
t.Fatalf("done key %+v, want the imports", v)
|
|
}
|
|
if len(logged) != 2 || strings.Join(logged[1].Imports, ",") != strings.Join(imports, ",") || len(logged[0].Imports) != 0 {
|
|
t.Fatalf("log %+v, want the imports on the end alone", logged)
|
|
}
|
|
}
|
|
|
|
// Design 26 (the lead's ruling on A2i's finding 2): the out-of-step files a contracts module's build module answers, in a
|
|
// failed step's result too, reach the log's end entry, sorted and each once, where the indexer raises its finding; a
|
|
// build that answers none names none.
|
|
func outOfStepFilesABuildAnswersReachTheLog(t *testing.T) {
|
|
for _, row := range []struct {
|
|
name string
|
|
fail bool
|
|
files []string
|
|
want string
|
|
}{
|
|
{"a passed build naming files", false, []string{"go/b.go", "go/a.go", "go/b.go"}, "go/a.go,go/b.go"},
|
|
{"a failed build naming files", true, []string{"ts/x.ts"}, "ts/x.ts"},
|
|
{"a build naming none", false, nil, ""},
|
|
} {
|
|
t.Run(row.name, func(t *testing.T) {
|
|
r := newRig(t, goBundle)
|
|
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
|
|
step := r.answer(a)
|
|
answer := map[string]any{}
|
|
_ = json.Unmarshal(step.Result, &answer)
|
|
if row.files != nil {
|
|
answer["out-of-step"] = row.files
|
|
}
|
|
step.Result, _ = json.Marshal(answer)
|
|
if row.fail {
|
|
step.State, step.Reason = buildstep.StepFailed, "the generated files are out of step"
|
|
}
|
|
return step
|
|
}
|
|
var logged []builds.BuildLogEntry
|
|
var mu sync.Mutex
|
|
r.b.Node, r.b.Log = "novox", func(e builds.BuildLogEntry) { mu.Lock(); logged = append(logged, e); mu.Unlock() }
|
|
r.consider(t, "modules/m")
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if len(logged) != 2 || strings.Join(logged[1].OutOfStep, ",") != row.want || len(logged[0].OutOfStep) != 0 {
|
|
t.Fatalf("log %+v, want the end naming %q", logged, row.want)
|
|
}
|
|
})
|
|
}
|
|
}
|