Skip to content

Commit

Permalink
Try to fix registry handler test
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Mar 4, 2022
1 parent 46a24ae commit fe83502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 15 additions & 8 deletions cmd/lifecycle/platform/registry_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

ih "github.com/buildpacks/imgutil/testhelpers"
Expand All @@ -28,9 +29,10 @@ func testRegistryHandler(t *testing.T, when spec.G, it spec.S) {
)

var (
registryValidator *platform.DefaultRegistryValidator
dockerConfigDir string
registry *ih.DockerRegistry
registryValidator *platform.DefaultRegistryValidator
dockerConfigDir string
registry *ih.DockerRegistry
containerBaseImage string
)

it.Before(func() {
Expand All @@ -48,7 +50,12 @@ func testRegistryHandler(t *testing.T, when spec.G, it spec.S) {
keychain, err := auth.DefaultKeychain(registry.RepoName("some-image"))
h.AssertNil(t, err)

createFixtures(t, registry, imageReadOnly, imageReadWrite, imageInaccessible)
if runtime.GOOS == "windows" {
containerBaseImage = "mcr.microsoft.com/windows/nanoserver:1809"
} else {
containerBaseImage = "scratch"
}
createFixtures(t, registry, containerBaseImage, imageReadOnly, imageReadWrite, imageInaccessible)
registry.SetReadOnly(imageReadOnly)
registry.SetReadWrite(imageReadWrite)
registry.SetInaccessible(imageInaccessible)
Expand Down Expand Up @@ -92,16 +99,16 @@ func testRegistryHandler(t *testing.T, when spec.G, it spec.S) {
})
}

func createFixtures(t *testing.T, registry *ih.DockerRegistry, imageNames ...string) {
func createFixtures(t *testing.T, registry *ih.DockerRegistry, baseImage string, imageNames ...string) {
for _, imageName := range imageNames {
buildRegistryImage(t, imageName, filepath.Join("testdata", "registry"), registry)
buildRegistryImage(t, imageName, filepath.Join("testdata", "registry"), registry, "--build-arg", "base_image="+baseImage)
}
}

func buildRegistryImage(t *testing.T, repoName, context string, registry *ih.DockerRegistry) string {
func buildRegistryImage(t *testing.T, repoName, context string, registry *ih.DockerRegistry, buildArgs ...string) string {
// Build image
regRepoName := registry.RepoName(repoName)
h.DockerBuild(t, regRepoName, context)
h.DockerBuild(t, regRepoName, context, h.WithArgs(buildArgs...))

// Push image
h.AssertNil(t, h.PushImage(h.DockerCli(t), regRepoName, registry.EncodedLabeledAuth()))
Expand Down
6 changes: 5 additions & 1 deletion cmd/lifecycle/platform/testdata/registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
FROM scratch
ARG base_image

FROM $base_image

LABEL some.label="some-label-value"

0 comments on commit fe83502

Please sign in to comment.