Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(action): add cnab/claim.json to op files #193

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.Invoca
if err != nil {
return nil, fmt.Errorf("failed to marshal bundle contents: %s", err)
}

files["/cnab/bundle.json"] = string(bundleBytes)

imgMap, err := getImageMap(c.Bundle)
Expand All @@ -203,6 +202,12 @@ func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.Invoca
}
files["/cnab/app/image-map.json"] = string(imgMap)

claimBytes, err := json.Marshal(c)
silvin-lubecki marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, fmt.Errorf("failed to marshal claim: %s", err)
}
files["/cnab/claim.json"] = string(claimBytes)

env["CNAB_ACTION"] = action
env["CNAB_BUNDLE_NAME"] = c.Bundle.Name
env["CNAB_BUNDLE_VERSION"] = c.Bundle.Version
Expand Down
14 changes: 12 additions & 2 deletions action/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,17 @@ func mockBundle() *bundle.Bundle {

func TestOpFromClaim(t *testing.T) {
c := newClaim()
// the monotonic clock reading from time.Now() proves problematic
// (it is lost after json.Unmarshal), so just set to static date for testing
created := time.Date(2020, time.March, 3, 1, 2, 3, 4, time.UTC)
c.Created = created
c.Modified = created
c.Parameters = map[string]interface{}{
"param_one": "oneval",
"param_two": "twoval",
"param_three": "threeval",
"param_array": []string{"first-value", "second-value"},
"param_object": map[string]string{
"param_array": []interface{}{"first-value", "second-value"},
"param_object": map[string]interface{}{
"first-key": "first-value",
"second-key": "second-value",
},
Expand Down Expand Up @@ -214,6 +219,7 @@ func TestOpFromClaim(t *testing.T) {
is.Equal(op.Files["/param/param_quoted_string"], `"quoted value"`)
is.Contains(op.Files, "/cnab/app/image-map.json")
is.Contains(op.Files, "/cnab/bundle.json")
is.Contains(op.Files, "/cnab/claim.json")
is.Contains(op.Outputs, "/tmp/some/path")

var imgMap map[string]bundle.Image
Expand All @@ -224,6 +230,10 @@ func TestOpFromClaim(t *testing.T) {
is.NoError(json.Unmarshal([]byte(op.Files["/cnab/bundle.json"]), &bundle))
is.Equal(c.Bundle, bundle)

var claim *claim.Claim
is.NoError(json.Unmarshal([]byte(op.Files["/cnab/claim.json"]), &claim))
is.Equal(c, claim)

is.Len(op.Parameters, 7)
is.Nil(op.Out)
}
Expand Down