Skip to content

Commit

Permalink
Merge pull request #512 from carolynvs/required-extensions
Browse files Browse the repository at this point in the history
Require the dependencies extension when any dependencies are defined
  • Loading branch information
carolynvs-msft authored Aug 14, 2019
2 parents a5e6ef9 + 0fc159d commit fb4fa4c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "github.com/deislabs/cnab-go"
version = "v0.3.1-beta1"

# TODO: update to actual release of deislabs/cnab-go
# override currently needed or else cnab-to-oci dep causes issues
[[override]]
name = "github.com/deislabs/cnab-go"
Expand Down
4 changes: 4 additions & 0 deletions pkg/cnab/config_adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (c *ManifestConverter) ToBundle() *bundle.Bundle {
b.Credentials = c.generateBundleCredentials()
b.Images = c.generateBundleImages()
b.Custom[config.CustomBundleKey] = c.GenerateStamp()

b.Custom[extensions.DependenciesKey] = c.generateDependencies()
if len(c.Manifest.Dependencies) > 0 {
b.RequiredExtensions = []string{extensions.DependenciesKey}
}

return b
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/cnab/config_adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ func TestManifestConverter_generateDependencies(t *testing.T) {
}

deps := a.generateDependencies()

require.NotNil(t, deps, "Dependencies should not be nil")
require.Len(t, deps.Requires, 3, "incorrect number of dependencies were generated")

Expand Down Expand Up @@ -476,6 +475,23 @@ func TestManifestConverter_generateDependencies(t *testing.T) {
}
}

func TestManifestConverter_RequiredExtensions(t *testing.T) {
c := config.NewTestConfig(t)
c.TestContext.AddTestFile("testdata/porter-with-deps.yaml", config.Name)

err := c.LoadManifest()
require.NoError(t, err)

a := ManifestConverter{
Context: c.Context,
Manifest: c.Manifest,
}

bun := a.ToBundle()

assert.Equal(t, []string{"io.cnab.dependencies"}, bun.RequiredExtensions)
}

func TestManifestConverter_GenerateCustomActionDefinitions(t *testing.T) {
c := config.NewTestConfig(t)
c.TestContext.AddTestFile("testdata/porter-with-custom-action.yaml", config.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cnab/extensions/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
DependenciesKey = "dependencies"
DependenciesKey = "io.cnab.dependencies"
DependenciesSchema = "https://cnab.io/specs/v1/dependencies.schema.json"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cnab/extensions/testdata/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"enabled": true,
"frequency": "daily"
},
"dependencies": {
"io.cnab.dependencies": {
"requires": {
"storage": {
"bundle": "somecloud/blob-storage"
Expand Down

0 comments on commit fb4fa4c

Please sign in to comment.