Say a build source only for the trunk's head, and hold what C, assembly and a new go.mod reach (hq ADR 0267, review)
A hand build of an older trunk commit said a closure lacking what was imported since, and the planner would have mapped the next merge onto it. C and assembly beside Go may include files below their directory, and a go.mod made above a package moves it out of its module: each is now held.
This commit is contained in:
@@ -16,12 +16,17 @@ import (
|
||||
type onTrunk struct {
|
||||
*recorded
|
||||
off bool
|
||||
// behind is a commit on the trunk that is not its head: an older commit built by hand.
|
||||
behind bool
|
||||
}
|
||||
|
||||
func (o onTrunk) run(ctx context.Context, dir, name string, args ...string) (string, error) {
|
||||
if name == "git" && len(args) > 0 && args[0] == "symbolic-ref" {
|
||||
return "origin/main\n", nil
|
||||
}
|
||||
if name == "git" && len(args) > 1 && args[0] == "rev-parse" && args[1] == "origin/main" && o.behind {
|
||||
return "feedfacefeedfacefeedfacefeedfacefeedface\n", nil
|
||||
}
|
||||
if name == "git" && len(args) > 0 && args[0] == "merge-base" && o.off {
|
||||
return "", os.ErrNotExist
|
||||
}
|
||||
@@ -47,14 +52,14 @@ const aProxy = `{"module":"route-proxy","version":"1",
|
||||
"context":{"repository":"https://forge.invalid/ctl.git","ref":"main"}},
|
||||
{"name":"trust","kind":"upstream","from":"alpine@sha256:` + "3333333333333333333333333333333333333333333333333333333333333333" + `"}]}}`
|
||||
|
||||
func buildTheProxy(t *testing.T, context_ map[string]string, off bool) (Result, *recorded, string) {
|
||||
func buildTheProxy(t *testing.T, context_ map[string]string, off bool, behind ...bool) (Result, *recorded, string) {
|
||||
t.Helper()
|
||||
r := &recorded{
|
||||
contents: map[string]string{"modules/route-proxy/" + ManifestName: aProxy, "modules/route-proxy/Dockerfile": "FROM scratch\nCOPY . .\n", "modules/route-proxy/README.md": "x"},
|
||||
secondary: map[string]map[string]string{"https://forge.invalid/ctl.git": context_},
|
||||
}
|
||||
workspace := t.TempDir()
|
||||
got, err := Build(context.Background(), onTrunk{r, off}.run, r,
|
||||
got, err := Build(context.Background(), onTrunk{r, off, len(behind) > 0 && behind[0]}.run, r,
|
||||
"https://forge.invalid/catalogue.git", "modules/route-proxy", "", workspace, nil, Npmrc{}, GitCredential{}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -112,12 +117,33 @@ func TestAnImageCompilingGoIsHandedItsBuildSourceAndSaysIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A build off the trunk says no build source: the planner maps a merge onto the trunk's.
|
||||
func TestABuildOffTheTrunkSaysNoBuildSource(t *testing.T) {
|
||||
// A build off the trunk, or of a trunk commit that is not its head, says no build source: the planner maps
|
||||
// a merge onto the trunk head's, and an older commit's closure lacks what was imported since.
|
||||
func TestABuildOffTheTrunksHeadSaysNoBuildSource(t *testing.T) {
|
||||
got, _, _ := buildTheProxy(t, aSharedRepository("one", "1"), true)
|
||||
if len(got.Sources) != 0 {
|
||||
t.Fatalf("a build off the trunk said %+v", got.Sources)
|
||||
}
|
||||
got, _, _ = buildTheProxy(t, aSharedRepository("one", "1"), false, true)
|
||||
if len(got.Sources) != 0 {
|
||||
t.Fatalf("a build of an older trunk commit said %+v", got.Sources)
|
||||
}
|
||||
}
|
||||
|
||||
// An archive of the module's whole directory holds every file of it.
|
||||
func TestAnArchiveOfTheWholeDirectoryHoldsIt(t *testing.T) {
|
||||
manifest := `{"module":"look","version":"1","build":{"artifacts":[{"name":"all","kind":"archive","from":"."}]},
|
||||
"resources":[{"id":"files","type":"archive","path":"/opt/look","artifact":"all"}]}`
|
||||
r := &recorded{contents: map[string]string{"modules/look/" + ManifestName: manifest, "modules/look/a/b.css": "x"}}
|
||||
got, err := Build(context.Background(), onTrunk{recorded: r}.run, r,
|
||||
"https://forge.invalid/catalogue.git", "modules/look", "", t.TempDir(), nil, Npmrc{}, GitCredential{}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.Sources) != 1 || !SourceHolds(got.Sources[0].Paths, "modules/look/a/b.css") ||
|
||||
SourceHolds(got.Sources[0].Paths, "modules/other/x") {
|
||||
t.Fatalf("sources %+v", got.Sources)
|
||||
}
|
||||
}
|
||||
|
||||
// A recipe reading past its build source fails, naming what it could not find — in the real docker build;
|
||||
@@ -128,7 +154,7 @@ func TestAnImageCompilingANonexistentPackageFails(t *testing.T) {
|
||||
"Dockerfile": "FROM scratch\n"},
|
||||
secondary: map[string]map[string]string{"https://forge.invalid/ctl.git": aSharedRepository("one", "1")},
|
||||
}
|
||||
_, err := Build(context.Background(), onTrunk{r, false}.run, r,
|
||||
_, err := Build(context.Background(), onTrunk{recorded: r}.run, r,
|
||||
"https://forge.invalid/catalogue.git", "", "", t.TempDir(), nil, Npmrc{}, GitCredential{}, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "nowhere") {
|
||||
t.Fatalf("a package that is not there built: %v", err)
|
||||
@@ -147,7 +173,7 @@ func TestAGoBundleSaysItsClosureAndAnUntoldImageNothing(t *testing.T) {
|
||||
r.contents[k] = v
|
||||
}
|
||||
held := map[string]string{"mesh-tools-go/build": "registry.invalid/mesh-tools-go/build@sha256:" + strings.Repeat("b", 64)}
|
||||
got, err := Build(context.Background(), onTrunk{r, false}.run, r,
|
||||
got, err := Build(context.Background(), onTrunk{recorded: r}.run, r,
|
||||
"https://forge.invalid/ctl.git", "", "", t.TempDir(), held, Npmrc{}, GitCredential{}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -165,7 +191,7 @@ func TestAGoBundleSaysItsClosureAndAnUntoldImageNothing(t *testing.T) {
|
||||
untold := `{"module":"ctl","version":"1","build":{"artifacts":[
|
||||
{"name":"server","kind":"image","from":"Dockerfile"}]}}`
|
||||
r = &recorded{contents: map[string]string{ManifestName: untold, "Dockerfile": "FROM scratch\n"}}
|
||||
got, err = Build(context.Background(), onTrunk{r, false}.run, r,
|
||||
got, err = Build(context.Background(), onTrunk{recorded: r}.run, r,
|
||||
"https://forge.invalid/ctl.git", "", "", t.TempDir(), nil, Npmrc{}, GitCredential{}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user