Skip to content

Commit

Permalink
Merge pull request #193 from vdice/feat/mount-claim-json
Browse files Browse the repository at this point in the history
feat(action): add cnab/claim.json to op files
  • Loading branch information
vdice authored Mar 4, 2020
2 parents 2a24d84 + d041a79 commit ccc659c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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)
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

0 comments on commit ccc659c

Please sign in to comment.