Skip to content

Commit

Permalink
Refactor acceptance test builder template
Browse files Browse the repository at this point in the history
- Better readability and consistent templating and optionals

Signed-off-by: Micah Young <ymicah@vmware.com>
  • Loading branch information
Micah Young authored and Javier Romero and Andrew Meyer committed May 5, 2020
1 parent 2f9f125 commit 7385b3a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
37 changes: 16 additions & 21 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,35 +1680,30 @@ func createBuilder(t *testing.T, runImageMirror, configDir, packPath, lifecycleP
[]string{"simple-layers-buildpack"},
)

// RENDER builder.toml
cfgData := fillTemplate(t, filepath.Join(configDir, "builder.toml"), map[string]interface{}{
"package_name": packageImageName,
})
err = ioutil.WriteFile(filepath.Join(tmpDir, "builder.toml"), []byte(cfgData), os.ModePerm)
h.AssertNil(t, err)

builderConfigFile, err := os.OpenFile(filepath.Join(tmpDir, "builder.toml"), os.O_RDWR|os.O_APPEND, os.ModePerm)
h.AssertNil(t, err)

// ADD run-image-mirrors
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("run-image-mirrors = [\"%s\"]\n", runImageMirror)))
h.AssertNil(t, err)
packageId := "simple/layers"

// ADD lifecycle
_, err = builderConfigFile.Write([]byte("[lifecycle]\n"))
h.AssertNil(t, err)

var lifecycleURI string
var lifecycleVersion string
if lifecyclePath != "" {
t.Logf("adding lifecycle path '%s' to builder config", lifecyclePath)
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("uri = \"%s\"\n", strings.ReplaceAll(lifecyclePath, `\`, `\\`))))
h.AssertNil(t, err)
lifecycleURI = strings.ReplaceAll(lifecyclePath, `\`, `\\`)
} else {
t.Logf("adding lifecycle version '%s' to builder config", lifecycleDescriptor.Info.Version.String())
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("version = \"%s\"\n", lifecycleDescriptor.Info.Version.String())))
h.AssertNil(t, err)
lifecycleVersion = lifecycleDescriptor.Info.Version.String()
}

builderConfigFile.Close()
// RENDER builder.toml
cfgData := fillTemplate(t, filepath.Join(configDir, "builder.toml"), map[string]interface{}{
"package_image_name": packageImageName,
"package_id": packageId,
"run_image_mirror": runImageMirror,
"lifecycle_uri": lifecycleURI,
"lifecycle_version": lifecycleVersion,
})

err = ioutil.WriteFile(filepath.Join(tmpDir, "builder.toml"), []byte(cfgData), os.ModePerm)
h.AssertNil(t, err)

// NAME BUILDER
bldr := registryConfig.RepoName("test/builder-" + h.RandString(10))
Expand Down
17 changes: 14 additions & 3 deletions acceptance/testdata/pack_fixtures/builder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
# noop-buildpack-2 has the same id but a different version compared to noop-buildpack
uri = "noop-buildpack-2.tgz"

{{- if .package_image_name}}
[[buildpacks]]
image = "{{ .package_name }}"
image = "{{.package_image_name}}"
{{- end}}

[[order]]
{{- if .package_id}}
[[order.group]]
id = "simple/layers"
id = "{{.package_id}}"
# intentionlly missing version to test support
{{- end}}

[[order.group]]
id = "read/env"
Expand All @@ -28,5 +32,12 @@
id = "pack.test.stack"
build-image = "pack-test/build"
run-image = "pack-test/run"
run-image-mirrors = ["{{.run_image_mirror}}"]

# run-image-mirror and lifecycle are appended by acceptance tests
[lifecycle]
{{- if .lifecycle_uri}}
uri = "{{.lifecycle_uri}}"
{{- end}}
{{- if .lifecycle_version}}
version = "{{.lifecycle_version}}"
{{- end}}

0 comments on commit 7385b3a

Please sign in to comment.