59 lines
2.4 KiB
Go
59 lines
2.4 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
func TestAWalkWhoseEveryBuildCameOutTheSameIsDone(t *testing.T) {
|
|
open := windowed(t)
|
|
endsItsLine(t)
|
|
asksRecorded(t)
|
|
ctx := t.Context()
|
|
inv := open.inventory
|
|
if err := inv.RecordBuild(ctx, inventory.Build{ID: "build-one", Repository: "novox/one", Ref: "main",
|
|
Module: "one", Commit: "c0", On: "builder", Asked: t0.Add(-time.Hour),
|
|
Made: []inventory.Artifact{{Name: "one", Kind: "image", Reference: "store/one@sha256:aaaa"}},
|
|
Sources: []inventory.BuildSource{{Paths: []string{"main.go", "go.mod"}}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// What runs: the module registered with that build's image (RegisteredHeld reads the module table).
|
|
if err := inv.RegisterModule(ctx, catalogue.Manifest{Module: "one", Version: "1", Resources: []map[string]any{
|
|
{"id": "app", "type": "container", "name": "one", "image": "store/one@sha256:aaaa"}}},
|
|
inventory.Source{Repository: "novox/one", Ref: "main", BuiltFrom: "c0", Asked: time.Now()}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pull := link.PullRef{Owner: "novox", Repo: "one", Number: 7}
|
|
was := checkedBuildsOf
|
|
checkedBuildsOf = func(context.Context, []link.PullRef) ([]link.CheckedBuild, error) {
|
|
return []link.CheckedBuild{{Pull: pull, Head: "headaaaaaaaa", Built: link.CheckBuilt{Module: "one", Key: "k",
|
|
Made: []link.MadeArtifact{{Name: "one", Kind: "image", Reference: "scratch/one@sha256:bbbb"}},
|
|
Same: "unchanged: its program is the same as running build one aaaa",
|
|
SameAs: map[string]string{"one": "10.0.0.1:5000/one@sha256:aaaa"}}}}, nil
|
|
}
|
|
t.Cleanup(func() { checkedBuildsOf = was })
|
|
code := repoMerge("one", "one1aaaaaaaa", t0)
|
|
code.Number, code.HeadSHA = 7, "headaaaaaaaa1111"
|
|
hear(t, open, code, t0.Add(time.Second))
|
|
cutAt(t, open, t0.Add(2*time.Minute))
|
|
ws, _ := walks(t, open)
|
|
if len(ws) != 1 {
|
|
t.Fatalf("walks: %+v", ws)
|
|
}
|
|
w := ws[0]
|
|
if w.State != inventory.PlanDone || len(w.Tiers) != 0 || len(w.Modules) != 0 {
|
|
t.Fatalf("the walk reads %s, tiers %v, modules %v; want done with nothing to walk", w.State, w.Tiers, w.Modules)
|
|
}
|
|
if w.Delivery == nil || !strings.Contains(w.Delivery.Unchanged["one"], "its program is the same as running build") {
|
|
t.Fatalf("the walk does not say one matched what runs: %+v", w.Delivery)
|
|
}
|
|
}
|