45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
//go:build integration
|
|
|
|
package builder
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func fingerprintOf(t *testing.T, manifest, tree string, mirrored string) string {
|
|
t.Helper()
|
|
r, workspace := aRepository(t, manifest, map[string]string{"modules/bus/Dockerfile": "ARG BASE\nFROM ${BASE}"})
|
|
r.contents["modules/bus/module.json"] = manifest
|
|
r.tree = tree
|
|
m := &mirroring{recorded: r, at: mirrored}
|
|
got, err := Build(context.Background(), r.run, m, "https://forge.invalid/catalogue.git", "modules/bus", "", workspace,
|
|
nil, Npmrc{}, GitCredential{}, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return got.Source
|
|
}
|
|
|
|
func TestASourceFingerprintNamesWhatABuildWasMadeFrom(t *testing.T) {
|
|
one := fingerprintOf(t, anImage, "aaaa", "registry-a:5000")
|
|
if !strings.HasPrefix(one, sourcePrefix) {
|
|
t.Fatalf("no fingerprint: %q", one)
|
|
}
|
|
// The same tree and base, the base copied to another registry address: one source.
|
|
if again := fingerprintOf(t, anImage, "aaaa", "registry-b:5000"); again != one {
|
|
t.Fatalf("one source has two fingerprints: %s %s", one, again)
|
|
}
|
|
// The module's tree changed: another source.
|
|
if changed := fingerprintOf(t, anImage, "bbbb", "registry-a:5000"); changed == one {
|
|
t.Fatal("a changed tree kept its fingerprint")
|
|
}
|
|
// The base moved: another source.
|
|
moved := strings.Replace(anImage, "1111111111111111111111111111111111111111111111111111111111111111",
|
|
"2222222222222222222222222222222222222222222222222222222222222222", 1)
|
|
if changed := fingerprintOf(t, moved, "aaaa", "registry-a:5000"); changed == one {
|
|
t.Fatal("a moved base kept its fingerprint")
|
|
}
|
|
}
|