Skip to content

Commit

Permalink
feat(claim.go): add Outputs field to Claim struct (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdice authored and jeremyrickard committed Jul 22, 2019
1 parent 3f015bf commit 4f62b69
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Claim struct {
Bundle *bundle.Bundle `json:"bundle"`
Result Result `json:"result"`
Parameters map[string]interface{} `json:"parameters"`
Outputs map[string]interface{} `json:"outputs"`
Files map[string]string `json:"files"`
RelocationMap bundle.ImageRelocationMap `json:"relocationMap"`
}
Expand All @@ -67,6 +68,7 @@ func New(name string) (*Claim, error) {
Status: StatusUnknown,
},
Parameters: map[string]interface{}{},
Outputs: map[string]interface{}{},
RelocationMap: bundle.ImageRelocationMap{},
}, nil
}
Expand Down
4 changes: 4 additions & 0 deletions claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func TestNew(t *testing.T) {
assert.Equal(t, "my_claim", claim.Name, "Name is set")
assert.Equal(t, "unknown", claim.Result.Status)
assert.Equal(t, "unknown", claim.Result.Action)

assert.Equal(t, map[string]interface{}{}, claim.Outputs)
assert.Equal(t, map[string]interface{}{}, claim.Parameters)
assert.Equal(t, bundle.ImageRelocationMap{}, claim.RelocationMap)
}

func TestUpdate(t *testing.T) {
Expand Down
45 changes: 45 additions & 0 deletions claim/claimstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,48 @@ func TestReadAll(t *testing.T) {
is.Equal("bar", claim2.Name)
is.Equal("baz", claim3.Name)
}

func TestCanUpdateOutputs(t *testing.T) {
is := assert.New(t)
claim, err := New("foo")
is.NoError(err)
is.Equal(map[string]interface{}{}, claim.Outputs)

tempDir, err := ioutil.TempDir("", "cnabgotest")
is.NoError(err, "Failed to create temp dir")
defer os.RemoveAll(tempDir)

storeDir := filepath.Join(tempDir, "claimstore")
store := NewClaimStore(crud.NewFileSystemStore(storeDir, "json"))

claim.Outputs = map[string]interface{}{
"foo-output": true,
"bar-output": "bar",
}

err = store.Store(*claim)
is.NoError(err, "Failed to store claim")

c, err := store.Read("foo")
is.NoError(err, "Failed to read claim")

want := map[string]interface{}{
"foo-output": true,
"bar-output": "bar",
}
is.Equal(want, c.Outputs, "Wrong outputs on claim")

claim.Outputs["bar-output"] = "baz"

err = store.Store(*claim)
is.NoError(err, "Failed to store claim")

c, err = store.Read("foo")
is.NoError(err, "Failed to read claim")

want = map[string]interface{}{
"foo-output": true,
"bar-output": "baz",
}
is.Equal(want, c.Outputs, "Wrong outputs on claim")
}

0 comments on commit 4f62b69

Please sign in to comment.