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) } }