From adac3069ad653211e8a39cb463c353d4149020e7 Mon Sep 17 00:00:00 2001 From: Ryan Moran Date: Wed, 3 Nov 2021 09:40:35 -0700 Subject: [PATCH] Updates tests to include coverage for spec api 0.6 changes --- internal/builder_config.go | 1 + internal/buildpack_config_test.go | 66 +++++++++++++++++++++-------- pack_test.go | 16 ++++++- testdata/example-cnb/buildpack.toml | 10 ++++- 4 files changed, 72 insertions(+), 21 deletions(-) diff --git a/internal/builder_config.go b/internal/builder_config.go index 3134549..f153e55 100644 --- a/internal/builder_config.go +++ b/internal/builder_config.go @@ -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"` diff --git a/internal/buildpack_config_test.go b/internal/buildpack_config_test.go index ee6fcfd..60d80ae 100644 --- a/internal/buildpack_config_test.go +++ b/internal/buildpack_config_test.go @@ -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]] @@ -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"}, @@ -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"}, @@ -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"] diff --git a/pack_test.go b/pack_test.go index 99ddc3e..46f7f24 100644 --- a/pack_test.go +++ b/pack_test.go @@ -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"] @@ -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"] diff --git a/testdata/example-cnb/buildpack.toml b/testdata/example-cnb/buildpack.toml index f49dae3..cd96292 100644 --- a/testdata/example-cnb/buildpack.toml +++ b/testdata/example-cnb/buildpack.toml @@ -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"