Skip to content

Commit d211135

Browse files
committed
add acceptance tests
Signed-off-by: dwillist <dthornton@vmware.com>
1 parent caa2a46 commit d211135

15 files changed

Lines changed: 241 additions & 16 deletions

File tree

acceptance/acceptance_test.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,64 @@ func testAcceptance(
673673
builderName = value
674674
})
675675

676+
when("complex builder", func() {
677+
it.Before(func() {
678+
// create our nested builder
679+
h.SkipIf(t, imageManager.HostOS() == "windows", "These tests are not yet compatible with Windows-based containers")
680+
h.SkipIf(t, !createBuilderPack.SupportsFeature(invoke.BuilderNoDuplicateLayers), "bug fixed in 0.18.0")
681+
682+
// create a task, handled by a 'task manager' which executes our pack commands during tests.
683+
// looks like this is used to de-dup tasks
684+
key := taskKey(
685+
"create-complex-builder",
686+
append(
687+
[]string{runImageMirror, createBuilderPackConfig.Path(), lifecycle.Identifier()},
688+
createBuilderPackConfig.FixturePaths()...,
689+
)...,
690+
)
691+
// run task on taskmanager and save output, in case there are future calls to the same task
692+
// likely all our changes need to go on the createBuilderPack.
693+
value, err := suiteManager.RunTaskOnceString(key, func() (string, error) {
694+
return createComplexBuilder(
695+
t,
696+
assert,
697+
createBuilderPack,
698+
lifecycle,
699+
buildpackManager,
700+
runImageMirror,
701+
)
702+
})
703+
assert.Nil(err)
704+
705+
// register task to be run to 'clean up' a task
706+
suiteManager.RegisterCleanUp("clean-"+key, func() error {
707+
imageManager.CleanupImages(value)
708+
return nil
709+
})
710+
builderName = value
711+
712+
output := pack.RunSuccessfully(
713+
"config", "run-image-mirrors", "add", "pack-test/run", "--mirror", "some-registry.com/pack-test/run1")
714+
assertOutput := assertions.NewOutputAssertionManager(t, output)
715+
assertOutput.ReportsSuccesfulRunImageMirrorsAdd("pack-test/run", "some-registry.com/pack-test/run1")
716+
})
717+
when("builder has duplicate buildpacks", func() {
718+
it("buildpack layers have no duplication", func() {
719+
out, _, err := dockerCli.ImageInspectWithRaw(context.Background(), builderName)
720+
assert.Nil(err)
721+
722+
layerSet := map[string]interface{}{}
723+
for _, layer := range out.RootFS.Layers {
724+
_, ok := layerSet[layer]
725+
if ok {
726+
t.Fatalf("duplicate layer found in builder %s", layer)
727+
}
728+
layerSet[layer] = true
729+
}
730+
})
731+
})
732+
})
733+
676734
when("builder.toml is invalid", func() {
677735
it("displays an error", func() {
678736
builderConfigPath := createBuilderPack.FixtureManager().FixtureLocation("invalid_builder.toml")
@@ -1910,6 +1968,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
19101968
it.Before(func() {
19111969
// create our nested builder
19121970
h.SkipIf(t, imageManager.HostOS() == "windows", "These tests are not yet compatible with Windows-based containers")
1971+
h.SkipIf(t, !pack.SupportsFeature(invoke.BuilderNoDuplicateLayers), "bug fixed in 0.18.0")
19131972

19141973
// create a task, handled by a 'task manager' which executes our pack commands during tests.
19151974
// looks like this is used to de-dup tasks
@@ -2426,12 +2485,14 @@ func createComplexBuilder(t *testing.T,
24262485
packageImageName := registryConfig.RepoName("nested-level-1-buildpack-" + h.RandString(8))
24272486
nestedLevelTwoBuildpackName := registryConfig.RepoName("nested-level-2-buildpack-" + h.RandString(8))
24282487
simpleLayersBuildpackName := registryConfig.RepoName("simple-layers-buildpack-" + h.RandString(8))
2488+
simpleLayersBuildpackDifferentShaName := registryConfig.RepoName("simple-layers-buildpack-different-name-" + h.RandString(8))
24292489

24302490
templateMapping["package_id"] = "simple/nested-level-1"
24312491
templateMapping["package_image_name"] = packageImageName
24322492
templateMapping["nested_level_1_buildpack"] = packageImageName
24332493
templateMapping["nested_level_2_buildpack"] = nestedLevelTwoBuildpackName
24342494
templateMapping["simple_layers_buildpack"] = simpleLayersBuildpackName
2495+
templateMapping["simple_layers_buildpack_different_sha"] = simpleLayersBuildpackDifferentShaName
24352496

24362497
fixtureManager := pack.FixtureManager()
24372498

@@ -2452,6 +2513,7 @@ func createComplexBuilder(t *testing.T,
24522513
nestedLevelTwoConfigFile,
24532514
templateMapping,
24542515
)
2516+
24552517
err = nestedLevelTwoConfigFile.Close()
24562518
assert.Nil(err)
24572519

@@ -2481,11 +2543,20 @@ func createComplexBuilder(t *testing.T,
24812543
),
24822544
)
24832545

2484-
defer imageManager.CleanupImages(packageImageName, nestedLevelTwoBuildpackName, simpleLayersBuildpackName)
2546+
simpleLayersDifferentShaBuildpack := buildpacks.NewPackageImage(
2547+
t,
2548+
pack,
2549+
simpleLayersBuildpackDifferentShaName,
2550+
fixtureManager.FixtureLocation("simple-layers-buildpack-different-sha_package.toml"),
2551+
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayersDifferentSha),
2552+
)
2553+
2554+
defer imageManager.CleanupImages(packageImageName, nestedLevelTwoBuildpackName, simpleLayersBuildpackName, simpleLayersBuildpackDifferentShaName)
24852555

24862556
builderBuildpacks = append(
24872557
builderBuildpacks,
24882558
packageImageBuildpack,
2559+
simpleLayersDifferentShaBuildpack,
24892560
)
24902561

24912562
buildpackManager.PrepareBuildpacks(tmpDir, builderBuildpacks...)

acceptance/buildpacks/archive_buildpack.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ func (a archiveBuildpack) createTgz(sourceDir string) (string, error) {
8484
}
8585

8686
var (
87-
SimpleLayersParent = &archiveBuildpack{name: "simple-layers-parent-buildpack"}
88-
SimpleLayers = &archiveBuildpack{name: "simple-layers-buildpack"}
89-
InternetCapable = &archiveBuildpack{name: "internet-capable-buildpack"}
90-
ReadVolume = &archiveBuildpack{name: "read-volume-buildpack"}
91-
ReadWriteVolume = &archiveBuildpack{name: "read-write-volume-buildpack"}
92-
ArchiveNotInBuilder = &archiveBuildpack{name: "not-in-builder-buildpack"}
93-
Noop = &archiveBuildpack{name: "noop-buildpack"}
94-
Noop2 = &archiveBuildpack{name: "noop-buildpack-2"}
95-
OtherStack = &archiveBuildpack{name: "other-stack-buildpack"}
96-
ReadEnv = &archiveBuildpack{name: "read-env-buildpack"}
97-
NestedLevelOne = &archiveBuildpack{name: "nested-level-1-buildpack"}
98-
NestedLevelTwo = &archiveBuildpack{name: "nested-level-2-buildpack"}
87+
SimpleLayersParent = &archiveBuildpack{name: "simple-layers-parent-buildpack"}
88+
SimpleLayers = &archiveBuildpack{name: "simple-layers-buildpack"}
89+
SimpleLayersDifferentSha = &archiveBuildpack{name: "simple-layers-buildpack-different-sha"}
90+
InternetCapable = &archiveBuildpack{name: "internet-capable-buildpack"}
91+
ReadVolume = &archiveBuildpack{name: "read-volume-buildpack"}
92+
ReadWriteVolume = &archiveBuildpack{name: "read-write-volume-buildpack"}
93+
ArchiveNotInBuilder = &archiveBuildpack{name: "not-in-builder-buildpack"}
94+
Noop = &archiveBuildpack{name: "noop-buildpack"}
95+
Noop2 = &archiveBuildpack{name: "noop-buildpack-2"}
96+
OtherStack = &archiveBuildpack{name: "other-stack-buildpack"}
97+
ReadEnv = &archiveBuildpack{name: "read-env-buildpack"}
98+
NestedLevelOne = &archiveBuildpack{name: "nested-level-1-buildpack"}
99+
NestedLevelTwo = &archiveBuildpack{name: "nested-level-2-buildpack"}
99100
)

acceptance/buildpacks/package_image_buildpack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (p PackageImage) Prepare(sourceDir, _ string) error {
8383
packArgs = append(packArgs, "--publish")
8484
}
8585

86+
p.testObject.Log("packaging image: ", p.name)
8687
output := p.pack.RunSuccessfully("buildpack", append([]string{"package"}, packArgs...)...)
8788
assertOutput := assertions.NewOutputAssertionManager(p.testObject, output)
8889
if p.publish {

acceptance/invoke/pack.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,16 @@ type Feature int
214214

215215
const (
216216
InspectRemoteImage = iota
217+
BuilderNoDuplicateLayers
217218
)
218219

219220
var featureTests = map[Feature]func(i *PackInvoker) bool{
220221
InspectRemoteImage: func(i *PackInvoker) bool {
221222
return i.laterThan("0.17.0")
222223
},
224+
BuilderNoDuplicateLayers: func(i *PackInvoker) bool {
225+
return i.laterThan("0.18.0")
226+
},
223227
}
224228

225229
func (i *PackInvoker) SupportsFeature(f Feature) bool {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
echo "---> Build: Simple Layers Different Sha Buildpack"
4+
5+
set -o errexit
6+
set -o nounset
7+
set -o pipefail
8+
9+
launch_dir=$1
10+
11+
## makes a launch layer
12+
echo "making launch layer"
13+
14+
# Add color line, to test for --no-color
15+
echo "Color: Styled"
16+
17+
mkdir "$launch_dir/launch-layer"
18+
echo "Launch Dep Contents" > "$launch_dir/launch-layer/launch-dep"
19+
ln -snf "$launch_dir/launch-layer" launch-deps
20+
echo "launch = true" > "$launch_dir/launch-layer.toml"
21+
22+
## makes a cached launch layer
23+
if [[ ! -f "$launch_dir/cached-launch-layer.toml" ]]; then
24+
echo "making cached launch layer"
25+
mkdir "$launch_dir/cached-launch-layer"
26+
echo "Cached Dep Contents" > "$launch_dir/cached-launch-layer/cached-dep"
27+
ln -snf "$launch_dir/cached-launch-layer" cached-deps
28+
echo "launch = true" > "$launch_dir/cached-launch-layer.toml"
29+
echo "cache = true" >> "$launch_dir/cached-launch-layer.toml"
30+
else
31+
echo "reusing cached launch layer"
32+
ln -snf "$launch_dir/cached-launch-layer" cached-deps
33+
fi
34+
35+
## adds a process
36+
cat <<EOF > "$launch_dir/launch.toml"
37+
[[processes]]
38+
type = "web"
39+
command = "./run"
40+
args = ["8080"]
41+
42+
[[processes]]
43+
type = "hello"
44+
command = "echo"
45+
args = ["hello", "world"]
46+
direct = true
47+
EOF
48+
49+
echo "---> Done"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@echo off
2+
echo --- Build: Simple Layers Different Sha Buildpack
3+
4+
set launch_dir=%1
5+
6+
:: makes a launch layer
7+
echo making launch layer %launch_dir%\launch-layer
8+
mkdir %launch_dir%\launch-layer
9+
echo Launch Dep Contents > "%launch_dir%\launch-layer\launch-dep
10+
mklink /j launch-deps %launch_dir%\launch-layer
11+
echo launch = true > %launch_dir%\launch-layer.toml
12+
13+
:: makes a cached launch layer
14+
if not exist %launch_dir%\cached-launch-layer.toml (
15+
echo making cached launch layer %launch_dir%\cached-launch-layer
16+
mkdir %launch_dir%\cached-launch-layer
17+
echo Cached Dep Contents > %launch_dir%\cached-launch-layer\cached-dep
18+
mklink /j cached-deps %launch_dir%\cached-launch-layer
19+
echo launch = true > %launch_dir%\cached-launch-layer.toml
20+
echo cache = true >> %launch_dir%\cached-launch-layer.toml
21+
) else (
22+
echo reusing cached launch layer %launch_dir%\cached-launch-layer
23+
mklink /j cached-deps %launch_dir%\cached-launch-layer
24+
)
25+
26+
:: adds a process
27+
(
28+
echo [[processes]]
29+
echo type = "web"
30+
echo command = '.\run'
31+
echo args = ["8080"]
32+
echo.
33+
echo [[processes]]
34+
echo type = "hello"
35+
echo command = "cmd"
36+
echo args = ["/c", "echo hello world"]
37+
echo direct = true
38+
) > %launch_dir%\launch.toml
39+
40+
echo --- Done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
## always detect
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
:: always detect
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Just some extra content to change the sha256 of this buildpack :)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
api = "0.2"
2+
3+
[buildpack]
4+
id = "simple/layers"
5+
version = "simple-layers-version"
6+
name = "Simple Layers Buildpack"
7+
8+
[[stacks]]
9+
id = "pack.test.stack"

0 commit comments

Comments
 (0)