From 4f62b69709950d5a3c831bfdba1c3ba3e2416ccd Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Mon, 22 Jul 2019 10:29:08 -0600 Subject: [PATCH] feat(claim.go): add Outputs field to Claim struct (#66) --- claim/claim.go | 2 ++ claim/claim_test.go | 4 ++++ claim/claimstore_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/claim/claim.go b/claim/claim.go index c58064c9..0087d1cf 100644 --- a/claim/claim.go +++ b/claim/claim.go @@ -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"` } @@ -67,6 +68,7 @@ func New(name string) (*Claim, error) { Status: StatusUnknown, }, Parameters: map[string]interface{}{}, + Outputs: map[string]interface{}{}, RelocationMap: bundle.ImageRelocationMap{}, }, nil } diff --git a/claim/claim_test.go b/claim/claim_test.go index a7790e6e..8a8f9543 100644 --- a/claim/claim_test.go +++ b/claim/claim_test.go @@ -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) { diff --git a/claim/claimstore_test.go b/claim/claimstore_test.go index ff36e392..9fae96f8 100644 --- a/claim/claimstore_test.go +++ b/claim/claimstore_test.go @@ -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") +}