41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
//go:build integration
|
|
|
|
package builder
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestABuildSaysWhatItMirroredEvenWhenItFails(t *testing.T) {
|
|
// A recipe that reaches for an image nobody declared is refused — after the base was copied.
|
|
r, workspace := aRepository(t, anImage, map[string]string{
|
|
"modules/bus/Dockerfile": "ARG BASE\nFROM ${BASE}\nCOPY --from=vendor/other:1 /x /x"})
|
|
r.contents["modules/bus/module.json"] = anImage
|
|
r.tree = "aaaa"
|
|
m := &mirroring{recorded: r, at: "registry-a:5000"}
|
|
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("a recipe fetching an undeclared image was built")
|
|
}
|
|
want := "registry-a:5000/upstream/docker.io/vendor/server@sha256:" + strings.Repeat("1", 64)
|
|
if len(got.Mirrored) != 1 || got.Mirrored[0] != want {
|
|
t.Fatalf("a failed build said it mirrored %v, want [%s]", got.Mirrored, want)
|
|
}
|
|
|
|
// And a build that works says it too.
|
|
r2, workspace2 := aRepository(t, anImage, map[string]string{"modules/bus/Dockerfile": "ARG BASE\nFROM ${BASE}"})
|
|
r2.contents["modules/bus/module.json"] = anImage
|
|
r2.tree = "aaaa"
|
|
ok, err := Build(context.Background(), r2.run, &mirroring{recorded: r2, at: "registry-a:5000"},
|
|
"https://forge.invalid/catalogue.git", "modules/bus", "", workspace2, nil, Npmrc{}, GitCredential{}, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(ok.Mirrored) != 1 || ok.Mirrored[0] != want {
|
|
t.Fatalf("a build said it mirrored %v, want [%s]", ok.Mirrored, want)
|
|
}
|
|
}
|