Skip to content

Commit

Permalink
add deprecation_date parsing into cargo
Browse files Browse the repository at this point in the history
[#170753637]

Co-authored-by: Josh Zarrabi <[email protected]>
  • Loading branch information
dwillist and joshzarrabi committed Mar 24, 2020
1 parent 78a2dcf commit 075ad72
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
17 changes: 11 additions & 6 deletions cargo/buildpack_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"testing"
"time"

"github.com/cloudfoundry/packit/cargo"
"github.com/sclevine/spec"
Expand Down Expand Up @@ -34,6 +35,7 @@ include_files = ["some-include-file", "other-include-file"]
pre_package = "some-pre-package-script.sh"
[[metadata.dependencies]]
deprecation_date = 2020-06-01T00:00:00Z
id = "some-dependency"
name = "Some Dependency"
sha256 = "shasum"
Expand All @@ -56,6 +58,8 @@ pre_package = "some-pre-package-script.sh"

context("Parse", func() {
it("parses a given buildpack.toml", func() {
deprecationDate, err := time.Parse(time.RFC3339, "2020-06-01T00:00:00Z")
Expect(err).NotTo(HaveOccurred())
config, err := parser.Parse(path)
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(cargo.Config{
Expand All @@ -73,12 +77,13 @@ pre_package = "some-pre-package-script.sh"
PrePackage: "some-pre-package-script.sh",
Dependencies: []cargo.ConfigMetadataDependency{
{
ID: "some-dependency",
Name: "Some Dependency",
SHA256: "shasum",
Stacks: []string{"io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.tiny"},
URI: "http://some-url",
Version: "1.2.3",
DeprecationDate: deprecationDate,
ID: "some-dependency",
Name: "Some Dependency",
SHA256: "shasum",
Stacks: []string{"io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.tiny"},
URI: "http://some-url",
Version: "1.2.3",
},
},
},
Expand Down
14 changes: 8 additions & 6 deletions cargo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cargo
import (
"encoding/json"
"io"
"time"

"github.com/BurntSushi/toml"
)
Expand Down Expand Up @@ -33,12 +34,13 @@ type ConfigMetadata struct {
}

type ConfigMetadataDependency struct {
ID string `toml:"id" json:"id"`
Name string `toml:"name" json:"name"`
SHA256 string `toml:"sha256" json:"sha256"`
Stacks []string `toml:"stacks" json:"stacks"`
URI string `toml:"uri" json:"uri"`
Version string `toml:"version" json:"version"`
DeprecationDate time.Time `toml:"deprecation_date" json:"deprecation_date"`
ID string `toml:"id" json:"id"`
Name string `toml:"name" json:"name"`
SHA256 string `toml:"sha256" json:"sha256"`
Stacks []string `toml:"stacks" json:"stacks"`
URI string `toml:"uri" json:"uri"`
Version string `toml:"version" json:"version"`
}

func EncodeConfig(writer io.Writer, config Config) error {
Expand Down
20 changes: 13 additions & 7 deletions cargo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"strings"
"testing"
"time"

"github.com/cloudfoundry/packit/cargo"
"github.com/sclevine/spec"
Expand All @@ -26,7 +27,10 @@ func testConfig(t *testing.T, context spec.G, it spec.S) {

context("EncodeConfig", func() {
it("encodes the config to TOML", func() {
err := cargo.EncodeConfig(buffer, cargo.Config{
deprecationDate, err := time.Parse(time.RFC3339, "2020-06-01T00:00:00Z")
Expect(err).NotTo(HaveOccurred())

err = cargo.EncodeConfig(buffer, cargo.Config{
API: "0.2",
Buildpack: cargo.ConfigBuildpack{
ID: "some-buildpack-id",
Expand All @@ -47,12 +51,13 @@ func testConfig(t *testing.T, context spec.G, it spec.S) {
PrePackage: "some-pre-package-script.sh",
Dependencies: []cargo.ConfigMetadataDependency{
{
ID: "some-dependency",
Name: "Some Dependency",
SHA256: "shasum",
Stacks: []string{"io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.tiny"},
URI: "http://some-url",
Version: "1.2.3",
DeprecationDate: deprecationDate,
ID: "some-dependency",
Name: "Some Dependency",
SHA256: "shasum",
Stacks: []string{"io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.tiny"},
URI: "http://some-url",
Version: "1.2.3",
},
},
DefaultVersions: map[string]string{
Expand All @@ -75,6 +80,7 @@ pre_package = "some-pre-package-script.sh"
some-dependency = "1.2.x"
[[metadata.dependencies]]
deprecation_date = "2020-06-01T00:00:00Z"
id = "some-dependency"
name = "Some Dependency"
sha256 = "shasum"
Expand Down
3 changes: 3 additions & 0 deletions cargo/jam/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
some-dependency = "some-default-version"
[[metadata.dependencies]]
deprecation_date = "2019-04-01T00:00:00Z"
id = "some-dependency"
name = "Some Dependency"
sha256 = "shasum"
Expand All @@ -105,6 +106,7 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
version = "1.2.3"
[[metadata.dependencies]]
deprecation_date = "2022-04-01T00:00:00Z"
id = "other-dependency"
name = "Other Dependency"
sha256 = "shasum"
Expand Down Expand Up @@ -216,6 +218,7 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
some-dependency = "some-default-version"
[[metadata.dependencies]]
deprecation_date = "2019-04-01T00:00:00Z"
id = "some-dependency"
name = "Some Dependency"
sha256 = "f058c8bf6b65b829e200ef5c2d22fde0ee65b96c1fbd1b88869be133aafab64a"
Expand Down
2 changes: 2 additions & 0 deletions cargo/jam/testdata/example-cnb/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ api = "0.2"
some-dependency = "some-default-version"

[[metadata.dependencies]]
deprecation_date = 2019-04-01T00:00:00Z
id = "some-dependency"
name = "Some Dependency"
sha256 = "shasum"
Expand All @@ -20,6 +21,7 @@ api = "0.2"
version = "1.2.3"

[[metadata.dependencies]]
deprecation_date = 2022-04-01T00:00:00Z
id = "other-dependency"
name = "Other Dependency"
sha256 = "shasum"
Expand Down

0 comments on commit 075ad72

Please sign in to comment.