Files
mesh-delivery/modules/mesh-delivery-checker/internal/check/binaries_test.go
T

58 lines
2.0 KiB
Go

package check
import (
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliverycheckerclient"
"git.novox.be/novox/mesh-delivery/sdk/buildstep"
)
func TestAChangeWhoseFetchReportsProgramsFailsNamingEachFile(t *testing.T) { // 1577
prog := func(p ...string) []buildstep.Program {
var out []buildstep.Program // no program is the omitted empty list of the typed answer
for _, f := range p {
path, commit, _ := strings.Cut(f, "@") // `path@commit`: added by a commit of the branch and removed later
out = append(out, buildstep.Program{Path: path, Kind: "ELF", Commit: commit})
}
return out
}
for _, c := range []struct {
name string
programs []buildstep.Program
fail []string // paths named; none passes
}{
{"none found", prog(), nil},
{"one program", prog("modules/m/m"), []string{"modules/m/m"}},
{"two programs", prog("a/x", "b/y"), []string{"a/x", "b/y"}},
{"added and removed in the branch", prog("gone/prog@0123456789abcdef0123"), []string{"gone/prog: a compiled program added in 0123456789ab and removed later: it stays in history; squash the branch (issue 1577)"}},
} {
b := newBench(t)
b.fetch.Merge, b.fetch.Programs = "mmmm", c.programs
cs := caseOf(t, pullOf(repoA, 7, head1))
v := b.judge(t, cs).Verdict
if len(cs.Notes()) > 0 {
t.Errorf("%s: notes = %v: a merge with no program is not a fetch that reported none", c.name, cs.Notes())
}
if len(c.fail) == 0 {
if v.State != meshdeliverycheckerclient.VerdictPass {
t.Errorf("%s: verdict = %+v", c.name, v)
}
continue
}
if v.State != meshdeliverycheckerclient.VerdictFail {
t.Errorf("%s: verdict = %+v, want a failure", c.name, v)
continue
}
for _, p := range c.fail {
want := p
if !strings.Contains(p, " added in ") {
want = p + ": a compiled program is build output: remove it and add it to .gitignore (issue 1577)"
}
if !strings.Contains(v.Failed.Words, want) {
t.Errorf("%s: words %q do not name %s", c.name, v.Failed.Words, p)
}
}
}
}