Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
- 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 <narellano@vmware.com>
  • Loading branch information
natalieparellano committed May 20, 2024
1 parent 6f50db6 commit f2cd826
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})
})
Expand Down
11 changes: 9 additions & 2 deletions pkg/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"strings"

Expand Down Expand Up @@ -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 <image> 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, "")
}
}
Expand Down

0 comments on commit f2cd826

Please sign in to comment.