Skip to content

Commit

Permalink
Read OS platform from config-file during "pack package-buildpack"
Browse files Browse the repository at this point in the history
- acceptance tests

Signed-off-by: Anthony Emengo <[email protected]>
  • Loading branch information
Anthony Emengo committed Oct 27, 2020
1 parent 3801e27 commit b3ff0d8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 52 deletions.
79 changes: 55 additions & 24 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
})
Expand All @@ -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)
Expand All @@ -276,6 +273,7 @@ func testWithoutSpecificBuilderRequirement(
map[string]interface{}{
"BuildpackURI": buildpackURI,
"PackageName": nestedPackageName,
"OS": os,
},
)

Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -314,7 +315,7 @@ func testWithoutSpecificBuilderRequirement(
t,
pack,
nestedPackageName,
simplePackageConfigPath,
packageTomlPath,
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
),
),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -1324,7 +1329,6 @@ func testAcceptance(
buildpacks.FolderSimpleLayersParent,
buildpacks.FolderSimpleLayers,
),
buildpacks.WithOS(dockerHostOS()),
)

buildpackManager.PrepareBuildpacks(tmpDir, packageFile)
Expand Down Expand Up @@ -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),
)

Expand Down Expand Up @@ -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...")
Expand Down
7 changes: 0 additions & 7 deletions acceptance/buildpacks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (b BuildpackManager) PrepareBuildpacks(destination string, buildpacks ...Te
}

type Modifiable interface {
SetOS(string)
SetPublish()
SetBuildpacks([]TestBuildpack)
}
Expand All @@ -70,9 +69,3 @@ func WithPublish() PackageModifier {
p.SetPublish()
}
}

func WithOS(osVal string) PackageModifier {
return func(p Modifiable) {
p.SetOS(osVal)
}
}
9 changes: 0 additions & 9 deletions acceptance/buildpacks/package_file_buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down
9 changes: 0 additions & 9 deletions acceptance/buildpacks/package_image_buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion acceptance/testdata/pack_fixtures/package.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[buildpack]
uri = "simple-layers-buildpack.tgz"
uri = "simple-layers-buildpack.tgz"

[platform]
os = "{{ .OS }}"
5 changes: 4 additions & 1 deletion acceptance/testdata/pack_fixtures/package_aggregate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
uri = "{{ .BuildpackURI }}"

[[dependencies]]
image = "{{ .PackageName }}"
image = "{{ .PackageName }}"

[platform]
os = "{{ .OS }}"
5 changes: 4 additions & 1 deletion acceptance/testdata/pack_fixtures/package_for_build_cmd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
uri = "simple-layers-parent-buildpack"

[[dependencies]]
uri = "simple-layers-buildpack"
uri = "simple-layers-buildpack"

[platform]
os = "{{ .OS }}"

0 comments on commit b3ff0d8

Please sign in to comment.