-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer to builder run image mirror if not publishing (daemon case)
* Refactor and add to Build tests Signed-off-by: David Freilich <[email protected]>
- Loading branch information
Showing
5 changed files
with
197 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package pack | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/heroku/color" | ||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
"github.com/buildpacks/pack/internal/builder" | ||
ilogging "github.com/buildpacks/pack/internal/logging" | ||
"github.com/buildpacks/pack/logging" | ||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
func TestCommon(t *testing.T) { | ||
color.Disable(true) | ||
defer color.Disable(false) | ||
spec.Run(t, "build", testCommon, spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testCommon(t *testing.T, when spec.G, it spec.S) { | ||
when("#resolveRunImage", func() { | ||
var ( | ||
subject *Client | ||
outBuf bytes.Buffer | ||
logger logging.Logger | ||
runImageName string | ||
defaultRegistry string | ||
defaultMirror string | ||
gcrRegistry string | ||
gcrRunMirror string | ||
stackInfo builder.StackMetadata | ||
) | ||
|
||
it.Before(func() { | ||
logger = ilogging.NewLogWithWriters(&outBuf, &outBuf) | ||
|
||
var err error | ||
subject, err = NewClient(WithLogger(logger)) | ||
h.AssertNil(t, err) | ||
|
||
defaultRegistry = "default.registry.io" | ||
runImageName = "stack/run" | ||
defaultMirror = defaultRegistry + "/" + runImageName | ||
gcrRegistry = "gcr.io" | ||
gcrRunMirror = gcrRegistry + "/" + runImageName | ||
stackInfo = builder.StackMetadata{ | ||
RunImage: builder.RunImageMetadata{ | ||
Image: runImageName, | ||
Mirrors: []string{ | ||
defaultMirror, gcrRunMirror, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
when("passed specific run image", func() { | ||
it("selects that run image", func() { | ||
runImgFlag := "flag/passed-run-image" | ||
runImageName := subject.resolveRunImage(runImgFlag, defaultRegistry, "", stackInfo, nil, false) | ||
h.AssertEq(t, runImageName, runImgFlag) | ||
}) | ||
}) | ||
|
||
when("publish is true", func() { | ||
it("defaults to run-image in registry publishing to", func() { | ||
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, nil, true) | ||
h.AssertEq(t, runImageName, gcrRunMirror) | ||
}) | ||
|
||
it("prefers config defined run image mirror to stack defined run image mirror", func() { | ||
configMirrors := map[string][]string{ | ||
runImageName: []string{defaultRegistry + "/unique-run-img"}, | ||
} | ||
runImageName := subject.resolveRunImage("", defaultRegistry, "", stackInfo, configMirrors, true) | ||
h.AssertNotEq(t, runImageName, defaultMirror) | ||
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img") | ||
}) | ||
|
||
it("returns a config mirror if no match to target registry", func() { | ||
configMirrors := map[string][]string{ | ||
runImageName: []string{defaultRegistry + "/unique-run-img"}, | ||
} | ||
runImageName := subject.resolveRunImage("", "test.registry.io", "", stackInfo, configMirrors, true) | ||
h.AssertNotEq(t, runImageName, defaultMirror) | ||
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img") | ||
}) | ||
}) | ||
|
||
// If publish is false, we are using the local daemon, and want to match to the builder registry | ||
when("publish is false", func() { | ||
it("defaults to run-image in registry publishing to", func() { | ||
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, nil, false) | ||
h.AssertEq(t, runImageName, defaultMirror) | ||
h.AssertNotEq(t, runImageName, gcrRunMirror) | ||
}) | ||
|
||
it("prefers config defined run image mirror to stack defined run image mirror", func() { | ||
configMirrors := map[string][]string{ | ||
runImageName: []string{defaultRegistry + "/unique-run-img"}, | ||
} | ||
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, configMirrors, false) | ||
h.AssertNotEq(t, runImageName, defaultMirror) | ||
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img") | ||
}) | ||
|
||
it("returns a config mirror if no match to target registry", func() { | ||
configMirrors := map[string][]string{ | ||
runImageName: []string{defaultRegistry + "/unique-run-img"}, | ||
} | ||
runImageName := subject.resolveRunImage("", defaultRegistry, "test.registry.io", stackInfo, configMirrors, false) | ||
h.AssertNotEq(t, runImageName, defaultMirror) | ||
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img") | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters