From b3ff0d8ebf34bfa72560202b0b42244d99830095 Mon Sep 17 00:00:00 2001 From: Anthony Emengo Date: Tue, 27 Oct 2020 11:57:05 -0400 Subject: [PATCH] Read OS platform from config-file during "pack package-buildpack" - acceptance tests Signed-off-by: Anthony Emengo --- acceptance/acceptance_test.go | 79 +++++++++++++------ acceptance/buildpacks/manager.go | 7 -- .../buildpacks/package_file_buildpack.go | 9 --- .../buildpacks/package_image_buildpack.go | 9 --- .../testdata/pack_fixtures/package.toml | 5 +- .../pack_fixtures/package_aggregate.toml | 5 +- .../pack_fixtures/package_for_build_cmd.toml | 5 +- 7 files changed, 67 insertions(+), 52 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 237e5c685f..c55a27f675 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -232,9 +232,9 @@ func testWithoutSpecificBuilderRequirement( when("package-buildpack", func() { var ( - tmpDir string - simplePackageConfigPath string - buildpackManager buildpacks.BuildpackManager + tmpDir string + buildpackManager buildpacks.BuildpackManager + simplePackageConfigFixtureName = "package.toml" ) it.Before(func() { @@ -247,9 +247,6 @@ func testWithoutSpecificBuilderRequirement( tmpDir, err = ioutil.TempDir("", "package-buildpack-tests") assert.Nil(err) - simplePackageConfigPath = filepath.Join(tmpDir, "package.toml") - h.CopyFile(t, pack.FixtureManager().FixtureLocation("package.toml"), simplePackageConfigPath) - buildpackManager = buildpacks.NewBuildpackManager(t, assert) buildpackManager.PrepareBuildpacks(tmpDir, buildpacks.SimpleLayersParent, buildpacks.SimpleLayers) }) @@ -265,7 +262,7 @@ func testWithoutSpecificBuilderRequirement( } - generateAggregatePackageToml := func(buildpackURI, nestedPackageName string) string { + generateAggregatePackageToml := func(buildpackURI, nestedPackageName, os string) string { t.Helper() packageTomlFile, err := ioutil.TempFile(tmpDir, "package_aggregate-*.toml") assert.Nil(err) @@ -276,6 +273,7 @@ func testWithoutSpecificBuilderRequirement( map[string]interface{}{ "BuildpackURI": buildpackURI, "PackageName": nestedPackageName, + "OS": os, }, ) @@ -287,7 +285,9 @@ func testWithoutSpecificBuilderRequirement( when("no --format is provided", func() { it("creates the package as image", func() { packageName := "test/package-" + h.RandString(10) - output := pack.RunSuccessfully("package-buildpack", packageName, "-c", simplePackageConfigPath) + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) + + output := pack.RunSuccessfully("package-buildpack", packageName, "-c", packageTomlPath) assertions.NewOutputAssertionManager(t, output).ReportsPackageCreation(packageName) defer h.DockerRmi(dockerCli, packageName) @@ -301,7 +301,8 @@ func testWithoutSpecificBuilderRequirement( nestedPackageName := "test/package-" + h.RandString(10) packageName := "test/package-" + h.RandString(10) - aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName) + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) + aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, dockerHostOS()) packageBuildpack := buildpacks.NewPackageImage( t, @@ -314,7 +315,7 @@ func testWithoutSpecificBuilderRequirement( t, pack, nestedPackageName, - simplePackageConfigPath, + packageTomlPath, buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers), ), ), @@ -330,27 +331,26 @@ func testWithoutSpecificBuilderRequirement( it("publishes image to registry", func() { h.SkipIf(t, !pack.Supports("package-buildpack --os"), "os not supported") + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) nestedPackageName := registryConfig.RepoName("test/package-" + h.RandString(10)) nestedPackage := buildpacks.NewPackageImage( t, pack, nestedPackageName, - simplePackageConfigPath, + packageTomlPath, buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers), buildpacks.WithPublish(), - buildpacks.WithOS(dockerHostOS()), ) buildpackManager.PrepareBuildpacks(tmpDir, nestedPackage) defer h.DockerRmi(dockerCli, nestedPackageName) - aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName) + aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, dockerHostOS()) packageName := registryConfig.RepoName("test/package-" + h.RandString(10)) output := pack.RunSuccessfully( "package-buildpack", packageName, "-c", aggregatePackageToml, "--publish", - "--os", dockerHostOS(), ) defer h.DockerRmi(dockerCli, packageName) assertions.NewOutputAssertionManager(t, output).ReportsPackagePublished(packageName) @@ -367,17 +367,18 @@ func testWithoutSpecificBuilderRequirement( when("--pull-policy=never", func() { it("should use local image", func() { + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) nestedPackageName := "test/package-" + h.RandString(10) nestedPackage := buildpacks.NewPackageImage( t, pack, nestedPackageName, - simplePackageConfigPath, + packageTomlPath, buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers), ) buildpackManager.PrepareBuildpacks(tmpDir, nestedPackage) defer h.DockerRmi(dockerCli, nestedPackageName) - aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName) + aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, dockerHostOS()) packageName := registryConfig.RepoName("test/package-" + h.RandString(10)) defer h.DockerRmi(dockerCli, packageName) @@ -393,18 +394,19 @@ func testWithoutSpecificBuilderRequirement( }) it("should not pull image from registry", func() { + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) nestedPackageName := registryConfig.RepoName("test/package-" + h.RandString(10)) nestedPackage := buildpacks.NewPackageImage( t, pack, nestedPackageName, - simplePackageConfigPath, + packageTomlPath, buildpacks.WithPublish(), buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers), ) buildpackManager.PrepareBuildpacks(tmpDir, nestedPackage) defer h.DockerRmi(dockerCli, nestedPackageName) - aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName) + aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, dockerHostOS()) packageName := registryConfig.RepoName("test/package-" + h.RandString(10)) defer h.DockerRmi(dockerCli, packageName) @@ -425,11 +427,12 @@ func testWithoutSpecificBuilderRequirement( }) it("creates the package", func() { + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, dockerHostOS()) destinationFile := filepath.Join(tmpDir, "package.cnb") output, err := pack.Run( "package-buildpack", destinationFile, "--format", "file", - "-c", simplePackageConfigPath, + "-c", packageTomlPath, ) assert.Nil(err) assertions.NewOutputAssertionManager(t, output).ReportsPackageCreation(destinationFile) @@ -535,16 +538,17 @@ func testWithoutSpecificBuilderRequirement( fmt.Sprintf("buildpack-%s.cnb", h.RandString(8)), ) + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, "package_for_build_cmd.toml", dockerHostOS()) + packageFile := buildpacks.NewPackageFile( t, pack, packageFileLocation, - pack.FixtureManager().FixtureLocation("package_for_build_cmd.toml"), + packageTomlPath, buildpacks.WithRequiredBuildpacks( buildpacks.FolderSimpleLayersParent, buildpacks.FolderSimpleLayers, ), - buildpacks.WithOS(dockerHostOS()), ) buildpackManager.PrepareBuildpacks(tmpDir, packageFile) @@ -567,13 +571,14 @@ func testWithoutSpecificBuilderRequirement( when("buildpack image", func() { when("inspect-buildpack", func() { it("succeeds", func() { + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, "package_for_build_cmd.toml", dockerHostOS()) packageImageName := registryConfig.RepoName("buildpack-" + h.RandString(8)) packageImage := buildpacks.NewPackageImage( t, pack, packageImageName, - pack.FixtureManager().FixtureLocation("package_for_build_cmd.toml"), + packageTomlPath, buildpacks.WithRequiredBuildpacks( buildpacks.FolderSimpleLayersParent, buildpacks.FolderSimpleLayers, @@ -1324,7 +1329,6 @@ func testAcceptance( buildpacks.FolderSimpleLayersParent, buildpacks.FolderSimpleLayers, ), - buildpacks.WithOS(dockerHostOS()), ) buildpackManager.PrepareBuildpacks(tmpDir, packageFile) @@ -2251,13 +2255,14 @@ func createBuilder( buildpacks.ReadEnv, } + packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, "package.toml", dockerHostOS()) packageImageName := registryConfig.RepoName("simple-layers-package-image-buildpack-" + h.RandString(8)) packageImageBuildpack := buildpacks.NewPackageImage( t, pack, packageImageName, - pack.FixtureManager().FixtureLocation("package.toml"), + packageTomlPath, buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers), ) @@ -2311,6 +2316,32 @@ func createBuilder( return bldr, nil } +func generatePackageTomlWithOS( + t *testing.T, + assert h.AssertionManager, + pack *invoke.PackInvoker, + tmpDir string, + fixtureName string, + platform_os string, +) string { + t.Helper() + + packageTomlFile, err := ioutil.TempFile(tmpDir, "package-*.toml") + assert.Nil(err) + + pack.FixtureManager().TemplateFixtureToFile( + fixtureName, + packageTomlFile, + map[string]interface{}{ + "OS": platform_os, + }, + ) + + assert.Nil(packageTomlFile.Close()) + + return packageTomlFile.Name() +} + func createStack(t *testing.T, dockerCli client.CommonAPIClient, runImageMirror string) error { t.Helper() t.Log("creating stack images...") diff --git a/acceptance/buildpacks/manager.go b/acceptance/buildpacks/manager.go index f3777bd42e..5987155c93 100644 --- a/acceptance/buildpacks/manager.go +++ b/acceptance/buildpacks/manager.go @@ -53,7 +53,6 @@ func (b BuildpackManager) PrepareBuildpacks(destination string, buildpacks ...Te } type Modifiable interface { - SetOS(string) SetPublish() SetBuildpacks([]TestBuildpack) } @@ -70,9 +69,3 @@ func WithPublish() PackageModifier { p.SetPublish() } } - -func WithOS(osVal string) PackageModifier { - return func(p Modifiable) { - p.SetOS(osVal) - } -} diff --git a/acceptance/buildpacks/package_file_buildpack.go b/acceptance/buildpacks/package_file_buildpack.go index 3b6d5cb616..ab1694524b 100644 --- a/acceptance/buildpacks/package_file_buildpack.go +++ b/acceptance/buildpacks/package_file_buildpack.go @@ -21,11 +21,6 @@ type PackageFile struct { destination string sourceConfigLocation string buildpacks []TestBuildpack - os string -} - -func (p *PackageFile) SetOS(os string) { - p.os = os } func (p *PackageFile) SetBuildpacks(buildpacks []TestBuildpack) { @@ -81,10 +76,6 @@ func (p PackageFile) Prepare(sourceDir, _ string) error { "--format", "file", } - if p.os != "" { - packArgs = append(packArgs, "--os", p.os) - } - output := p.pack.RunSuccessfully("package-buildpack", packArgs...) if !strings.Contains(output, fmt.Sprintf("Successfully created package '%s'", p.destination)) { diff --git a/acceptance/buildpacks/package_image_buildpack.go b/acceptance/buildpacks/package_image_buildpack.go index fc616176a9..ddd882b548 100644 --- a/acceptance/buildpacks/package_image_buildpack.go +++ b/acceptance/buildpacks/package_image_buildpack.go @@ -23,11 +23,6 @@ type PackageImage struct { sourceConfigLocation string buildpacks []TestBuildpack publish bool - os string -} - -func (p *PackageImage) SetOS(os string) { - p.os = os } func (p *PackageImage) SetBuildpacks(buildpacks []TestBuildpack) { @@ -88,10 +83,6 @@ func (p PackageImage) Prepare(sourceDir, _ string) error { packArgs = append(packArgs, "--publish") } - if p.os != "" { - packArgs = append(packArgs, "--os", p.os) - } - output := p.pack.RunSuccessfully("package-buildpack", packArgs...) assertOutput := assertions.NewOutputAssertionManager(p.testObject, output) diff --git a/acceptance/testdata/pack_fixtures/package.toml b/acceptance/testdata/pack_fixtures/package.toml index 28694e6601..6368266c38 100644 --- a/acceptance/testdata/pack_fixtures/package.toml +++ b/acceptance/testdata/pack_fixtures/package.toml @@ -1,2 +1,5 @@ [buildpack] -uri = "simple-layers-buildpack.tgz" \ No newline at end of file +uri = "simple-layers-buildpack.tgz" + +[platform] +os = "{{ .OS }}" \ No newline at end of file diff --git a/acceptance/testdata/pack_fixtures/package_aggregate.toml b/acceptance/testdata/pack_fixtures/package_aggregate.toml index 096dc5afb5..e6a5e2c980 100644 --- a/acceptance/testdata/pack_fixtures/package_aggregate.toml +++ b/acceptance/testdata/pack_fixtures/package_aggregate.toml @@ -2,4 +2,7 @@ uri = "{{ .BuildpackURI }}" [[dependencies]] -image = "{{ .PackageName }}" \ No newline at end of file +image = "{{ .PackageName }}" + +[platform] +os = "{{ .OS }}" \ No newline at end of file diff --git a/acceptance/testdata/pack_fixtures/package_for_build_cmd.toml b/acceptance/testdata/pack_fixtures/package_for_build_cmd.toml index 28defc25be..09676a90e0 100644 --- a/acceptance/testdata/pack_fixtures/package_for_build_cmd.toml +++ b/acceptance/testdata/pack_fixtures/package_for_build_cmd.toml @@ -2,4 +2,7 @@ uri = "simple-layers-parent-buildpack" [[dependencies]] -uri = "simple-layers-buildpack" \ No newline at end of file +uri = "simple-layers-buildpack" + +[platform] +os = "{{ .OS }}" \ No newline at end of file