mesh/delivery delivered
mesh/check pass 32542ebc14c3 on 7a88eb0a5609 | unit 122 run, 366 kept | integration 132 run, 414 kept | composition passed on novox
78 lines
3.0 KiB
Go
78 lines
3.0 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// unreadableAvahi is avahi's manifest with a field the running parser refuses: the shape of a manifest an older SDK could
|
|
// not read.
|
|
func unreadableAvahi(t *testing.T) string {
|
|
t.Helper()
|
|
raw := strings.Replace(catalogueManifest(t, "avahi"), `"version": "1",`, `"version": "1", "scope": "everything",`, 1)
|
|
if raw == catalogueManifest(t, "avahi") {
|
|
t.Fatal("the fixture has no version line")
|
|
}
|
|
return raw
|
|
}
|
|
|
|
func TestAMergeOfAnUnreadableManifestKeepsTheInputsBesideTheReason(t *testing.T) { // 1923/AC1
|
|
_, mods := newFormIndexer(t, mod{"avahi", unreadableAvahi(t)})
|
|
m, ok := moduleOf(t, mods, "avahi")
|
|
if !ok || !strings.HasPrefix(m.None2, "the manifest cannot be read: ") || m.FP2 != "" {
|
|
t.Fatalf("module = %+v, want the reason 'the manifest cannot be read' and no fingerprint", m)
|
|
}
|
|
if m.Inputs2 == nil || m.Inputs2.Tree != "tree-avahi" || m.Inputs2.Locks["go.sum"] != avahiGoSum {
|
|
t.Errorf("inputs = %+v, want the directory's tree and its lock hashes kept", m.Inputs2)
|
|
}
|
|
}
|
|
|
|
func TestAStaleUnreadableVerdictIsJudgedAgainAtStartAndAnotherReasonIsLeft(t *testing.T) { // 1923/AC2
|
|
ctx := context.Background()
|
|
// The fingerprint a merge of the readable manifest gives.
|
|
ixGood, good := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
|
|
reportToolchain(t, ixGood, "mesh-build-go", "novox", "go", "go1.27.1")
|
|
reportToolchain(t, ixGood, "mesh-build-go", "ace", "go", "go1.27.1")
|
|
want, _ := moduleOf(t, good, "avahi")
|
|
if want.FP2 == "" {
|
|
t.Fatalf("the readable manifest gives no fingerprint: %+v", want)
|
|
}
|
|
|
|
// The same module as an older SDK wrote it: the reason, the inputs kept at the merge, the manifest stored by digest.
|
|
ix, mods := newFormIndexer(t, mod{"avahi", unreadableAvahi(t)})
|
|
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
|
|
reportToolchain(t, ix, "mesh-build-go", "ace", "go", "go1.27.1")
|
|
stale, _ := moduleOf(t, mods, "avahi")
|
|
stale.Manifest = want.Manifest
|
|
ix.Manifests.(*memStore).put(want.Manifest, good2(t, ixGood, want.Manifest))
|
|
mods.put("avahi", mustEncode(t, stale))
|
|
if err := ix.Recompute(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _ := moduleOf(t, mods, "avahi")
|
|
if got.FP2 != want.FP2 || got.None2 != "" {
|
|
t.Errorf("after the start: fp2 %q none2 %q, want %q and no reason", got.FP2, got.None2, want.FP2)
|
|
}
|
|
|
|
// A manifest still unreadable keeps its value as it was.
|
|
ix2, mods2 := newFormIndexer(t, mod{"avahi", unreadableAvahi(t)})
|
|
before := string(mods2.vals["avahi"])
|
|
if err := ix2.Recompute(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if after := string(mods2.vals["avahi"]); after != before {
|
|
t.Errorf("a manifest still unreadable changed the value:\n%s\n%s", before, after)
|
|
}
|
|
}
|
|
|
|
// good2 is the stored manifest value of the digest in the indexer that merged the readable manifest.
|
|
func good2(t *testing.T, ix *Indexer, digest string) []byte {
|
|
t.Helper()
|
|
v, _, found, err := ix.Manifests.Get(context.Background(), digest)
|
|
if err != nil || !found {
|
|
t.Fatalf("manifests.%s: %v %v", digest, found, err)
|
|
}
|
|
return v
|
|
}
|