A build asked at a commit recorded that commit as the module's ref. Every merge after it failed to match the module and its plan left it out without a word, and every plan that rebuilt it asked for the same old commit again. Registration now keeps the branch the module followed (the default branch for a new one); matching and re-asking read a recorded commit as the default branch, which heals records already pinned this way; and a merge says which modules of its repository it leaves out because they follow another branch.
103 lines
4.3 KiB
Go
103 lines
4.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// A build's outcome is taken in the same way whoever hears it (novox/hq issue 176): recorded, and
|
|
// the module registered with its source as the seat and path when the request said so — never the
|
|
// URL. A definition naming an installation is recorded and not registered; a failure is recorded
|
|
// and said.
|
|
func TestABuildHeardIsRecordedAndRegistered(t *testing.T) {
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
manifest, _ := json.Marshal(map[string]any{"module": "shop", "version": "3"})
|
|
m, _, err := takeIn(ctx, open.inventory, link.BuildResult{
|
|
ID: "b-1", Repository: "http://forge.internal:20000/novox/shop.git", Path: "modules/shop",
|
|
Ref: "main", On: "anchor", Commit: "abcdef0123", Manifest: manifest,
|
|
Source: &link.SourceOnSeat{Seat: "git", Repository: "novox/shop"},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m.Module != "shop" {
|
|
t.Fatalf("registered %q", m.Module)
|
|
}
|
|
shelf, err := open.inventory.Catalogue(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, held := shelf["shop"]; !held {
|
|
t.Fatal("the module a heard build produced is not in the catalogue")
|
|
}
|
|
src, err := open.inventory.SourceOf(ctx, "shop")
|
|
if err != nil || src.Seat != "git" || src.Repository != "novox/shop" || src.BuiltFrom != "abcdef0123" {
|
|
t.Fatalf("the source is the seat and the path, never the URL: %+v %v", src, err)
|
|
}
|
|
builds, err := open.inventory.Builds(ctx, "shop", 5)
|
|
if err != nil || len(builds) != 1 || builds[0].ID != "b-1" {
|
|
t.Fatalf("the build is not recorded once: %v %v", builds, err)
|
|
}
|
|
|
|
named, _ := json.Marshal(map[string]any{"module": "idp", "version": "1", "resources": []any{
|
|
map[string]any{"id": "server", "type": "container", "image": "x@sha256:aa",
|
|
"env": map[string]any{"KC_HOSTNAME": "https://login.mesh-one.be"}}}})
|
|
_, _, err = takeIn(ctx, open.inventory, link.BuildResult{
|
|
ID: "b-2", Repository: "/r", On: "anchor", Commit: "0123456789", Manifest: named})
|
|
if err == nil || !strings.Contains(err.Error(), "does not register it") {
|
|
t.Fatalf("a definition naming an installation was taken in: %v", err)
|
|
}
|
|
if shelf, _ := open.inventory.Catalogue(ctx); shelf["idp"].Module != "" {
|
|
t.Fatal("the refused module was registered anyway")
|
|
}
|
|
if builds, _ := open.inventory.Builds(ctx, "idp", 5); len(builds) != 1 {
|
|
t.Fatalf("the refused build was not recorded: %v", builds)
|
|
}
|
|
|
|
_, _, err = takeIn(ctx, open.inventory, link.BuildResult{ID: "b-3", Repository: "/r", On: "anchor", Failed: "no compiler"})
|
|
if err == nil || !strings.Contains(err.Error(), "no compiler") {
|
|
t.Fatalf("a failure is said in the builder's words: %v", err)
|
|
}
|
|
}
|
|
|
|
// novox/hq 04-ISSUES/215: a build asked at a commit is recorded as built from that commit, and the
|
|
// module keeps following the branch it followed — a new one, the default branch.
|
|
func TestABuildAtACommitKeepsTheBranchTheModuleFollows(t *testing.T) {
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
manifest, _ := json.Marshal(map[string]any{"module": "unifi", "version": "1"})
|
|
result := func(id, ref, commit string) link.BuildResult {
|
|
return link.BuildResult{ID: id, Repository: "http://forge.internal:20000/novox/mesh-catalog.git",
|
|
Path: "modules/unifi", Ref: ref, On: "anchor", Commit: commit, Manifest: manifest,
|
|
Source: &link.SourceOnSeat{Seat: "git", Repository: "novox/mesh-catalog"}}
|
|
}
|
|
if _, _, err := takeIn(ctx, open.inventory, result("b-1", "main", "1111111aaaa")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := takeIn(ctx, open.inventory, result("b-2", "9c97a8a", "9c97a8a1d2c3")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
src, err := open.inventory.SourceOf(ctx, "unifi")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.Ref != "main" || src.BuiltFrom != "9c97a8a1d2c3" {
|
|
t.Errorf("after a build at a commit the module follows %q, built from %q; want main, 9c97a8a1d2c3", src.Ref, src.BuiltFrom)
|
|
}
|
|
|
|
// One new to the catalogue, first built at a commit, follows the default branch.
|
|
other, _ := json.Marshal(map[string]any{"module": "letta", "version": "1"})
|
|
r := result("b-3", "deadbeef", "deadbeefcafe")
|
|
r.Manifest, r.Path = other, "modules/letta"
|
|
if _, _, err := takeIn(ctx, open.inventory, r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src, _ := open.inventory.SourceOf(ctx, "letta"); src.Ref != "" {
|
|
t.Errorf("a module first built at a commit follows %q, want the default branch", src.Ref)
|
|
}
|
|
}
|