Skip to content

Commit

Permalink
Updates tests to include coverage for spec api 0.6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and ForestEckhardt committed Nov 3, 2021
1 parent a6b9346 commit adac306
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
1 change: 1 addition & 0 deletions internal/builder_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type BuilderConfigOrderGroup struct {
Version string `toml:"version,omitempty"`
Optional bool `toml:"optional,omitempty"`
}

type BuilderConfigStack struct {
ID string `toml:"id"`
BuildImage string `toml:"build-image"`
Expand Down
66 changes: 49 additions & 17 deletions internal/buildpack_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {
defer file.Close()

_, err = file.WriteString(`
api = "0.2"
api = "0.6"
[buildpack]
id = "some-composite-buildpack"
name = "Some Composite Buildpack"
version = "some-composite-buildpack-version"
id = "some-buildpack"
name = "Some Buildpack"
version = "some-buildpack-version"
homepage = "some-buildpack-homepage"
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-buildpack-license-type"
uri = "some-buildpack-license-uri"
[metadata]
include-files = ["buildpack.toml"]
include-files = [ "buildpack.toml" ]
[[order]]
[[order.group]]
Expand Down Expand Up @@ -62,11 +69,20 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {
config, err := internal.ParseBuildpackConfig(path)
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(internal.BuildpackConfig{
API: "0.2",
API: "0.6",
Buildpack: map[string]interface{}{
"id": "some-composite-buildpack",
"name": "Some Composite Buildpack",
"version": "some-composite-buildpack-version",
"id": "some-buildpack",
"name": "Some Buildpack",
"version": "some-buildpack-version",
"homepage": "some-buildpack-homepage",
"description": "some-buildpack-description",
"keywords": []interface{}{"some-buildpack-keyword"},
"licenses": []map[string]interface{}{
{
"type": "some-buildpack-license-type",
"uri": "some-buildpack-license-uri",
},
},
},
Metadata: map[string]interface{}{
"include-files": []interface{}{"buildpack.toml"},
Expand Down Expand Up @@ -141,11 +157,20 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {

it("overwrites the buildpack.toml configuration", func() {
err := internal.OverwriteBuildpackConfig(path, internal.BuildpackConfig{
API: "0.2",
API: "0.6",
Buildpack: map[string]interface{}{
"id": "some-composite-buildpack",
"name": "Some Composite Buildpack",
"version": "some-composite-buildpack-version",
"id": "some-buildpack",
"name": "Some Buildpack",
"version": "some-buildpack-version",
"homepage": "some-buildpack-homepage",
"description": "some-buildpack-description",
"keywords": []interface{}{"some-buildpack-keyword"},
"licenses": []map[string]interface{}{
{
"type": "some-buildpack-license-type",
"uri": "some-buildpack-license-uri",
},
},
},
Metadata: map[string]interface{}{
"include-files": []interface{}{"buildpack.toml"},
Expand Down Expand Up @@ -179,12 +204,19 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {
contents, err := os.ReadFile(path)
Expect(err).NotTo(HaveOccurred())
Expect(string(contents)).To(MatchTOML(`
api = "0.2"
api = "0.6"
[buildpack]
id = "some-composite-buildpack"
name = "Some Composite Buildpack"
version = "some-composite-buildpack-version"
id = "some-buildpack"
name = "Some Buildpack"
version = "some-buildpack-version"
homepage = "some-buildpack-homepage"
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-buildpack-license-type"
uri = "some-buildpack-license-uri"
[metadata]
include-files = ["buildpack.toml"]
Expand Down
16 changes: 14 additions & 2 deletions pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ func testPack(t *testing.T, context spec.G, it spec.S) {

contents, hdr, err := ExtractFile(file, "buildpack.toml")
Expect(err).NotTo(HaveOccurred())
Expect(contents).To(MatchTOML(`api = "0.2"
Expect(contents).To(MatchTOML(`api = "0.6"
[buildpack]
id = "some-buildpack-id"
name = "some-buildpack-name"
version = "some-version"
homepage = "some-homepage-link"
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-buildpack-license-type"
uri = "some-buildpack-license-uri"
[metadata]
include-files = ["bin/build", "bin/detect", "bin/link", "buildpack.toml", "generated-file"]
Expand Down Expand Up @@ -282,13 +288,19 @@ func testPack(t *testing.T, context spec.G, it spec.S) {

contents, hdr, err := ExtractFile(file, "buildpack.toml")
Expect(err).NotTo(HaveOccurred())
Expect(contents).To(MatchTOML(`api = "0.2"
Expect(contents).To(MatchTOML(`api = "0.6"
[buildpack]
id = "some-buildpack-id"
name = "some-buildpack-name"
version = "some-version"
homepage = "some-homepage-link"
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-buildpack-license-type"
uri = "some-buildpack-license-uri"
[metadata]
include-files = ["bin/build", "bin/detect", "bin/link", "buildpack.toml", "generated-file", "dependencies/f058c8bf6b65b829e200ef5c2d22fde0ee65b96c1fbd1b88869be133aafab64a"]
Expand Down
10 changes: 8 additions & 2 deletions testdata/example-cnb/buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
api = "0.2"
api = "0.6"

[buildpack]
id = "some-buildpack-id"
name = "some-buildpack-name"
version = "version-string"
homepage = "some-homepage-link"
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]

[[buildpack.licenses]]
type = "some-buildpack-license-type"
uri = "some-buildpack-license-uri"

[metadata]
include-files = ["bin/build", "bin/detect", "bin/link", "buildpack.toml", "generated-file"]
include-files = [ "bin/build", "bin/detect", "bin/link", "buildpack.toml", "generated-file" ]
pre-package = "./scripts/build.sh"
[metadata.default-versions]
some-dependency = "some-default-version"
Expand Down

0 comments on commit adac306

Please sign in to comment.