128 lines
6.6 KiB
Go
128 lines
6.6 KiB
Go
package meshdeliverycheckerclient
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
checker "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshdeliverychecker"
|
|
)
|
|
|
|
type verdict = checker.VerdictsByGroupHeadsValue
|
|
|
|
func passing() verdict {
|
|
return verdict{Group: "g", Heads: "0123456789ab", State: VerdictPass, Trunk: map[string]string{"novox/a": "c1"},
|
|
Levels: map[string]checker.VerdictsByGroupHeadsValueLevelsValue{LevelUnit: {Run: 3}, LevelIntegration: {Run: 1}}}
|
|
}
|
|
|
|
// The rules a verdict keeps to be written or read: each case edits a passing verdict and names what the refusal says.
|
|
func TestAVerdictIsRefusedForWhatAReaderCouldNotPlace(t *testing.T) {
|
|
if err := CheckVerdict(passing()); err != nil {
|
|
t.Fatalf("a passing verdict is refused: %v", err)
|
|
}
|
|
for name, c := range map[string]struct {
|
|
edit func(*verdict)
|
|
says string
|
|
}{
|
|
"no group": {func(v *verdict) { v.Group = "" }, "no group"},
|
|
"heads of 11 digits": {func(v *verdict) { v.Heads = "0123456789a" }, "12 lowercase hex"},
|
|
"an empty trunk head": {func(v *verdict) { v.Trunk["novox/a"] = "" }, "trunk head"},
|
|
"merged and read": {func(v *verdict) { v.Beside = map[string]string{"novox/a": "c2"} }, "trunk it merged and as a sibling"},
|
|
"nothing carried": {func(v *verdict) { v.CarriedFrom = map[string]string{"novox/a": "c1"} }, "nothing moved"},
|
|
"a running carry": {func(v *verdict) { v.State, v.CarriedFrom = VerdictRunning, map[string]string{"novox/a": "c0"} }, "carried from nothing"},
|
|
"a series to itself": {func(v *verdict) {
|
|
v.Series = []checker.VerdictsByGroupHeadsValueSeriesItem{{Module: "m", Artifact: "a", From: "0.1", To: "0.1"}}
|
|
}, "same series"},
|
|
"an unknown level": {func(v *verdict) { v.Levels["smoke"] = checker.VerdictsByGroupHeadsValueLevelsValue{} }, "smoke"},
|
|
"a negative count": {func(v *verdict) { v.Levels[LevelUnit] = checker.VerdictsByGroupHeadsValueLevelsValue{Run: -1} }, "negative"},
|
|
"a negative time": {func(v *verdict) { v.Took = &checker.VerdictsByGroupHeadsValueTook{Unit: -1} }, "negative"},
|
|
"a pass without a level": {func(v *verdict) { delete(v.Levels, LevelIntegration) }, "integration level"},
|
|
"a pass that failed": {func(v *verdict) { v.Failed = &checker.VerdictsByGroupHeadsValueFailed{Test: "T"} }, "names no failure"},
|
|
"failures of a pass": {func(v *verdict) { v.Failures = []checker.VerdictsByGroupHeadsValueFailuresItem{{Test: "T"}} }, "names no failures"},
|
|
"a fail naming nothing": {func(v *verdict) { v.State = VerdictFail }, "neither a test nor a machine"},
|
|
"an unknown state": {func(v *verdict) { v.State = "maybe" }, "maybe"},
|
|
"a composition passed without a commit": {func(v *verdict) {
|
|
v.Composition = &checker.VerdictsByGroupHeadsValueComposition{State: CompositionPass}
|
|
}, "mesh-sdk commit"},
|
|
"the same level over bound twice": {func(v *verdict) { v.OverBound = []string{LevelUnit, LevelUnit} }, "twice"},
|
|
} {
|
|
v := passing()
|
|
c.edit(&v)
|
|
if err := CheckVerdict(v); err == nil || !strings.Contains(err.Error(), c.says) {
|
|
t.Errorf("%s: %v, want a refusal saying %q", name, err, c.says)
|
|
}
|
|
}
|
|
failed := passing()
|
|
failed.State, failed.Failed = VerdictFail, &checker.VerdictsByGroupHeadsValueFailed{Machine: "ace"}
|
|
if err := CheckVerdict(failed); err != nil {
|
|
t.Errorf("a fail naming a machine is refused: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAKeptVerdictIsAPassOfAPackageAtALevel(t *testing.T) {
|
|
t.Run("a preview is refused for what a reader of candidates could not place", previewIsRefused)
|
|
ok := checker.KeptByLevelDigestValue{State: VerdictPass, Repository: "novox/mesh-sdk", Package: "./go/keys", Level: LevelUnit, Toolchain: "1.26.0", At: "2026-11-05T10:00:00Z"}
|
|
if err := CheckKept(ok); err != nil {
|
|
t.Fatalf("a kept pass is refused: %v", err)
|
|
}
|
|
for name, edit := range map[string]func(*checker.KeptByLevelDigestValue){
|
|
"a fail": func(k *checker.KeptByLevelDigestValue) { k.State = VerdictFail },
|
|
"no owner": func(k *checker.KeptByLevelDigestValue) { k.Repository = "mesh-sdk" },
|
|
"no package": func(k *checker.KeptByLevelDigestValue) { k.Package = "" },
|
|
"an unknown level": func(k *checker.KeptByLevelDigestValue) { k.Level = "smoke" },
|
|
"negative tests": func(k *checker.KeptByLevelDigestValue) { k.Tests = -1 },
|
|
"no toolchain": func(k *checker.KeptByLevelDigestValue) { k.Toolchain = "" },
|
|
"no time": func(k *checker.KeptByLevelDigestValue) { k.At = "" },
|
|
} {
|
|
k := ok
|
|
edit(&k)
|
|
if CheckKept(k) == nil {
|
|
t.Errorf("%s was taken", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A preview is refused for what a reader of candidates could not place.
|
|
func previewIsRefused(t *testing.T) {
|
|
good := func() checker.PreviewsByRepositoryHeadTrunkValue {
|
|
return checker.PreviewsByRepositoryHeadTrunkValue{Repository: "novox/a", Head: "h1", Trunk: "t1", Merge: "m1",
|
|
Modules: map[string]checker.PreviewsByRepositoryHeadTrunkValueModulesValue{"mod": {Tree: "tr", Manifest: strings.Repeat("a", 64),
|
|
Locks: map[string]string{"go.sum": "x"}, Paths: map[string]string{"src": "o1"}}}}
|
|
}
|
|
if err := CheckPreview(good()); err != nil {
|
|
t.Fatalf("a good preview is refused: %v", err)
|
|
}
|
|
for name, c := range map[string]struct {
|
|
edit func(*checker.PreviewsByRepositoryHeadTrunkValue)
|
|
says string
|
|
}{
|
|
"a repository with no owner": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) { p.Repository = "a" }, "<owner>/<name>"},
|
|
"a head with a dot": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) { p.Head = "h.1" }, "head"},
|
|
"a conflict with a merge": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) { p.Conflicts = []string{"f"} }, "in conflict"},
|
|
"no merge commit": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) { p.Merge = "" }, "no merge commit"},
|
|
"a module with no tree": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) {
|
|
m := p.Modules["mod"]
|
|
m.Tree = ""
|
|
p.Modules["mod"] = m
|
|
}, "no tree"},
|
|
"a short manifest digest": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) {
|
|
m := p.Modules["mod"]
|
|
m.Manifest = "abc"
|
|
p.Modules["mod"] = m
|
|
}, "manifest digest"},
|
|
"a path outside the module": {func(p *checker.PreviewsByRepositoryHeadTrunkValue) {
|
|
m := p.Modules["mod"]
|
|
m.Paths = map[string]string{"../x": "o"}
|
|
p.Modules["mod"] = m
|
|
}, "clean path"},
|
|
} {
|
|
p := good()
|
|
c.edit(&p)
|
|
if err := CheckPreview(p); err == nil || !strings.Contains(err.Error(), c.says) {
|
|
t.Errorf("%s: CheckPreview = %v, want it to say %q", name, err, c.says)
|
|
}
|
|
}
|
|
if err := CheckPreview(checker.PreviewsByRepositoryHeadTrunkValue{Repository: "novox/a", Head: "h", Trunk: "t", Conflicts: []string{"f"}}); err != nil {
|
|
t.Errorf("a head in conflict is refused: %v", err)
|
|
}
|
|
}
|