Files
mesh-controller/cmd/mesh-controller/try_integration_test.go
T

79 lines
3.1 KiB
Go

//go:build integration
package main
import (
"context"
"encoding/json"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"github.com/novox/mesh-controller/internal/inventory"
"github.com/novox/mesh-controller/internal/link"
)
func TestATrysOutcomeSetsNoStatusAndRegistersNothing(t *testing.T) {
said := &saidOnTheBus{}
checkEvents = said
defer func() { checkEvents = nil }()
for name, result := range map[string]link.BuildResult{
"a try": {ID: "build-1", Ref: "c0ffee", Checked: &link.CheckRequest{Owner: "novox", Repo: "a", Try: true},
Check: &link.CheckOutcome{Verdict: "pass", RepoCheck: &link.CheckLayer{Verdict: "fail", Summary: "failed"}}},
"a try that could not run": {ID: "build-2", Checked: &link.CheckRequest{Owner: "novox", Repo: "a", Try: true},
Failed: "cannot clone"},
// A build seat from before the mark echoes the ask without it: a check of no pull request and no
// group is still nobody's status.
"a try echoed by an older build seat": {ID: "build-3", Checked: &link.CheckRequest{Owner: "novox", Repo: "a"},
Check: &link.CheckOutcome{Verdict: "pass"}},
} {
if err := (builds{}).Built(context.Background(), result); err != nil {
t.Fatalf("%s: %v", name, err)
}
}
if len(said.events) != 0 {
t.Fatalf("a try's outcome was said for the forge: %v", said.events)
}
// A pull request's check is still said.
_ = (builds{}).Built(context.Background(), link.BuildResult{ID: "build-4", Checked: &link.CheckRequest{
Owner: "novox", Repo: "a", Number: 7}, Check: &link.CheckOutcome{Verdict: "pass"}})
if len(said.events) != 1 {
t.Fatalf("a pull request's check was said %d time(s)", len(said.events))
}
}
// ADR 0501 §5 (issue 1851): a try is asked of the checker, the head merged onto the trunk, never of build-agent:
// --store-only is the integration level, --tests passes on, the ask answers the checker's id.
func TestATryIsAskedOfTheChecker(t *testing.T) {
open := aMesh(t)
ctx := t.Context()
noBuildAsked(t)
if err := open.inventory.RegisterModule(ctx, catalogue.Manifest{Module: "sudo", Version: "1"},
inventory.Source{Repository: "novox/mesh-catalog", Seat: "git", Path: "modules/sudo", Ref: "main",
BuiltFrom: "c0", Head: "c0"}); err != nil {
t.Fatal(err)
}
wasForge, wasChecker := forgeCommit, askChecker
forgeCommit = func(context.Context, string, string, string) (string, string, error) {
return strings.Repeat("c", 40), "main", nil
}
var asked []map[string]any
askChecker = func(_ context.Context, tool string, args map[string]any, into any) error {
if tool != "checker_try" {
t.Errorf("asked %s", tool)
}
asked = append(asked, args)
return json.Unmarshal([]byte(`{"id":"try-1"}`), into)
}
t.Cleanup(func() { forgeCommit, askChecker = wasForge, wasChecker })
if err := tryCommand(ctx, []string{"novox/Mesh-Catalog", "fix/x", "--store-only", "--tests", "^TestX$"}); err != nil {
t.Fatal(err)
}
want := map[string]any{"repository": "novox/mesh-catalog", "head": strings.Repeat("c", 40), "trunk": "main",
"level": "integration", "tests": "^TestX$"}
if len(asked) != 1 || !reflect.DeepEqual(asked[0], want) {
t.Fatalf("the checker was asked %v, want %v", asked, want)
}
}