Skip to content

Commit

Permalink
Add acceptance test
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed Nov 13, 2023
1 parent d022a54 commit 5451248
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
38 changes: 38 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,44 @@ func testAcceptance(
assertBuildpackOutput := assertions.NewTestBuildpackOutputAssertionManager(t, output)
assertBuildpackOutput.ReportsBuildStep("Simple Layers Buildpack")
})

when("buildpackage is in a registry", func() {
it("adds the buildpacks to the builder and runs them", func() {
packageImageName = registryConfig.RepoName("buildpack-" + h.RandString(8))

packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, "package_for_build_cmd.toml", imageManager.HostOS())
packageImage := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
packageTomlPath,
buildpacks.WithRequiredBuildpacks(
buildpacks.BpFolderSimpleLayersParent,
buildpacks.BpFolderSimpleLayers,
),
buildpacks.WithPublish(),
)

buildpackManager.PrepareBuildModules(tmpDir, packageImage)

output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--buildpack", packageImageName,
)

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsAddingBuildpack(
"simple/layers/parent",
"simple-layers-parent-version",
)
assertOutput.ReportsAddingBuildpack("simple/layers", "simple-layers-version")
assertOutput.ReportsSuccessfulImageBuild(repoName)

assertBuildpackOutput := assertions.NewTestBuildpackOutputAssertionManager(t, output)
assertBuildpackOutput.ReportsBuildStep("Simple Layers Buildpack")
})
})
})

when("the argument is a buildpackage file", func() {
Expand Down
16 changes: 6 additions & 10 deletions pkg/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func NewFetcher(logger logging.Logger, docker DockerClient, opts ...FetcherOptio
}

var ErrNotFound = errors.New("not found")
var ErrPlatformNotMatch = errors.New("platform does not match")

func (f *Fetcher) Fetch(ctx context.Context, name string, options FetchOptions) (imgutil.Image, error) {
name, err := pname.TranslateRegistry(name, f.registryMirrors, f.logger)
Expand Down Expand Up @@ -110,10 +109,12 @@ func (f *Fetcher) Fetch(ctx context.Context, name string, options FetchOptions)
}

f.logger.Debugf("Pulling image %s", style.Symbol(name))
err = f.pullImage(ctx, name, options.Platform)
if errors.Is(err, ErrPlatformNotMatch) {
f.logger.Info(err.Error())
err = f.pullImage(ctx, name, "")
if err = f.pullImage(ctx, name, options.Platform); err != nil {
// 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") {
err = f.pullImage(ctx, name, "")
}
}
if err != nil && !errors.Is(err, ErrNotFound) {
return nil, err
Expand Down Expand Up @@ -197,11 +198,6 @@ func (f *Fetcher) pullImage(ctx context.Context, imageID string, platform string

err = jsonmessage.DisplayJSONMessagesStream(rc, &colorizedWriter{writer}, termFd, isTerm, nil)
if err != nil {
// 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") {
return errors.Wrap(ErrPlatformNotMatch, err.Error())
}
return err
}

Expand Down

0 comments on commit 5451248

Please sign in to comment.