From f2cd826552e324512c8e2440b7aa63d06c9f9849 Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Mon, 20 May 2024 16:00:00 -0400 Subject: [PATCH] Fix tests - WCOW units by checking for 'windows' in error string - LCOW acceptance by printing a log line and checking it instead of expecting an error Signed-off-by: Natalie Arellano --- acceptance/acceptance_test.go | 6 ++---- pkg/image/fetcher.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index c1cd457a8..53e82b791 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -2517,17 +2517,15 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] if hostArch := imageManager.HostArch(); hostArch == wrongArch { wrongArch = "amd64" } - // FIXME: on an M1 with emulation enabled this test might pass when we expect it to fail }) it("uses the builder with the desired platform", func() { - output, err := pack.Run( + output, _ := pack.Run( "build", repoName, "-p", filepath.Join("testdata", "mock_app"), "--platform", fmt.Sprintf("linux/%s", wrongArch), ) - h.AssertNotNil(t, err) - h.AssertContains(t, output, "was found but does not match the specified platform") + h.AssertContainsMatch(t, output, fmt.Sprintf("Pulling image '.+' with platform 'linux/%s'", wrongArch)) }) }) }) diff --git a/pkg/image/fetcher.go b/pkg/image/fetcher.go index 9c85da48f..5f59e1778 100644 --- a/pkg/image/fetcher.go +++ b/pkg/image/fetcher.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "encoding/json" + "fmt" "io" "strings" @@ -108,14 +109,20 @@ func (f *Fetcher) Fetch(ctx context.Context, name string, options FetchOptions) } } - f.logger.Debugf("Pulling image %s", style.Symbol(name)) + msg := fmt.Sprintf("Pulling image %s", style.Symbol(name)) + if options.Platform != "" { + msg = fmt.Sprintf("Pulling image %s with platform %s", style.Symbol(name), style.Symbol(options.Platform)) + } + f.logger.Debug(msg) if err = f.pullImage(ctx, name, options.Platform); err != nil { // FIXME: this matching is brittle and the fallback should be removed when https://github.com/buildpacks/pack/issues/2079 // has been fixed for a sufficient amount of time. // Sample error from docker engine: // `image with reference was found but does not match the specified platform: wanted linux/amd64, actual: linux` if strings.Contains(err.Error(), "does not match the specified platform") && - strings.HasSuffix(strings.TrimSpace(err.Error()), "actual: linux") { + (strings.HasSuffix(strings.TrimSpace(err.Error()), "actual: linux") || + strings.HasSuffix(strings.TrimSpace(err.Error()), "actual: windows")) { + f.logger.Debugf(fmt.Sprintf("Pulling image %s", style.Symbol(name))) err = f.pullImage(ctx, name, "") } }