Skip to content

Commit

Permalink
Sync claim status names with the spec (#197)
Browse files Browse the repository at this point in the history
* Sync claim status names with the spec

Synchronize the claim status names with recent spec changes from

* cnabio/cnab-spec#344
  * success -> succeeded
  * failure -> failed
* cnabio/cnab-spec#345
  * +cancelled
* cnabio/cnab-spec#340
  * +running

Signed-off-by: Carolyn Van Slyck <carolyn.vanslyck@microsoft.com>

* Match claim status const names with value

Update the const names to match the new values, and deprecate
StatusSuccess and StatusFailure.

Signed-off-by: Carolyn Van Slyck <carolyn.vanslyck@microsoft.com>
  • Loading branch information
carolynvs-msft authored Mar 12, 2020
1 parent eb7dfe1 commit 84c6ba8
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 29 deletions.
4 changes: 2 additions & 2 deletions action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (i *Install) Run(c *claim.Claim, creds credentials.Set, opCfgs ...Operation
outputErrors := setOutputsOnClaim(c, opResult.Outputs)

if err != nil {
c.Update(claim.ActionInstall, claim.StatusFailure)
c.Update(claim.ActionInstall, claim.StatusFailed)
c.Result.Message = err.Error()
return err
}
c.Update(claim.ActionInstall, claim.StatusSuccess)
c.Update(claim.ActionInstall, claim.StatusSucceeded)

return outputErrors
}
6 changes: 3 additions & 3 deletions action/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestInstall_Run(t *testing.T) {
Error: nil,
}}
assert.NoError(t, inst.Run(c, mockSet, out))
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Equal(t, claim.ActionInstall, c.Result.Action)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestInstall_Run(t *testing.T) {
},
}
assert.NoError(t, inst.Run(c, mockSet, out))
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Equal(t, claim.ActionInstall, c.Result.Action)
assert.Empty(t, c.Outputs)
})
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestInstall_Run(t *testing.T) {
},
}
assert.Error(t, inst.Run(c, mockSet, out))
assert.Equal(t, claim.StatusFailure, c.Result.Status)
assert.Equal(t, claim.StatusFailed, c.Result.Status)
assert.Equal(t, claim.ActionInstall, c.Result.Action)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})
Expand Down
4 changes: 2 additions & 2 deletions action/run_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func (i *RunCustom) Run(c *claim.Claim, creds credentials.Set, opCfgs ...Operati
outputErrors := setOutputsOnClaim(c, opResult.Outputs)

if err != nil {
c.Update(i.Action, claim.StatusFailure)
c.Update(i.Action, claim.StatusFailed)
c.Result.Message = err.Error()
return err
}
c.Update(i.Action, claim.StatusSuccess)
c.Update(i.Action, claim.StatusSucceeded)

return outputErrors
}
6 changes: 3 additions & 3 deletions action/run_custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRunCustom(t *testing.T) {
c := newClaim()
err := rc.Run(c, mockSet, out)
assert.NoError(t, err)
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Equal(t, "test", c.Result.Action)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestRunCustom(t *testing.T) {
err := rc.Run(c, mockSet, out)
assert.NoError(t, err)
assert.NotEqual(t, c.Created, c.Modified, "Claim was not updated with modified timestamp after custom action")
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Equal(t, "test", c.Result.Action)
assert.Empty(t, c.Outputs)
})
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestRunCustom(t *testing.T) {
assert.Error(t, err)
assert.NotEqual(t, "", c.Result.Message, "Expected error message in claim result message")
assert.Equal(t, "test", c.Result.Action)
assert.Equal(t, claim.StatusFailure, c.Result.Status)
assert.Equal(t, claim.StatusFailed, c.Result.Status)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})

Expand Down
4 changes: 2 additions & 2 deletions action/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (u *Uninstall) Run(c *claim.Claim, creds credentials.Set, opCfgs ...Operati
outputErrors := setOutputsOnClaim(c, opResult.Outputs)

if err != nil {
c.Update(claim.ActionUninstall, claim.StatusFailure)
c.Update(claim.ActionUninstall, claim.StatusFailed)
c.Result.Message = err.Error()
return err
}
c.Update(claim.ActionUninstall, claim.StatusSuccess)
c.Update(claim.ActionUninstall, claim.StatusSucceeded)

return outputErrors
}
6 changes: 3 additions & 3 deletions action/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestUninstall_Run(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, c.Created, c.Modified, "Claim was not updated with modified time stamp during uninstall after uninstall action")
assert.Equal(t, claim.ActionUninstall, c.Result.Action, "Claim result action not successfully updated.")
assert.Equal(t, claim.StatusSuccess, c.Result.Status, "Claim result status not successfully updated.")
assert.Equal(t, claim.StatusSucceeded, c.Result.Status, "Claim result status not successfully updated.")
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})

Expand Down Expand Up @@ -93,7 +93,7 @@ func TestUninstall_Run(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, c.Created, c.Modified, "Claim was not updated with modified time stamp during uninstall after uninstall action")
assert.Equal(t, claim.ActionUninstall, c.Result.Action, "Claim result action not successfully updated.")
assert.Equal(t, claim.StatusSuccess, c.Result.Status, "Claim result status not successfully updated.")
assert.Equal(t, claim.StatusSucceeded, c.Result.Status, "Claim result status not successfully updated.")
assert.Empty(t, c.Outputs)
})

Expand Down Expand Up @@ -123,7 +123,7 @@ func TestUninstall_Run(t *testing.T) {
assert.Error(t, err)
assert.NotEqual(t, "", c.Result.Message, "Expected error message in claim result message")
assert.Equal(t, claim.ActionUninstall, c.Result.Action)
assert.Equal(t, claim.StatusFailure, c.Result.Status)
assert.Equal(t, claim.StatusFailed, c.Result.Status)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})
}
4 changes: 2 additions & 2 deletions action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (u *Upgrade) Run(c *claim.Claim, creds credentials.Set, opCfgs ...Operation
outputErrors := setOutputsOnClaim(c, opResult.Outputs)

if err != nil {
c.Update(claim.ActionUpgrade, claim.StatusFailure)
c.Update(claim.ActionUpgrade, claim.StatusFailed)
c.Result.Message = err.Error()
return err
}
c.Update(claim.ActionUpgrade, claim.StatusSuccess)
c.Update(claim.ActionUpgrade, claim.StatusSucceeded)

return outputErrors
}
6 changes: 3 additions & 3 deletions action/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestUpgrade_Run(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, c.Created, c.Modified, "Claim was not updated with modified time stamp during upgrade action")
assert.Equal(t, claim.ActionUpgrade, c.Result.Action)
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Equal(t, map[string]interface{}{"some-output": "SOME CONTENT"}, c.Outputs)
})

Expand Down Expand Up @@ -89,7 +89,7 @@ func TestUpgrade_Run(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, c.Created, c.Modified, "Claim was not updated with modified time stamp during upgrade action")
assert.Equal(t, claim.ActionUpgrade, c.Result.Action)
assert.Equal(t, claim.StatusSuccess, c.Result.Status)
assert.Equal(t, claim.StatusSucceeded, c.Result.Status)
assert.Empty(t, c.Outputs)
})

Expand All @@ -114,7 +114,7 @@ func TestUpgrade_Run(t *testing.T) {
assert.Error(t, err)
assert.NotEmpty(t, c.Result.Message, "Expected error message in claim result message")
assert.Equal(t, claim.ActionUpgrade, c.Result.Action)
assert.Equal(t, claim.StatusFailure, c.Result.Status)
assert.Equal(t, claim.StatusFailed, c.Result.Status)
assert.Empty(t, c.Outputs)
})
}
18 changes: 13 additions & 5 deletions claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ const DefaultSchemaVersion = schemaversion.SchemaVersion("v1.0.0-WD")

// Status constants define the CNAB status fields on a Result.
const (
StatusSuccess = "success"
StatusFailure = "failure"
StatusPending = "pending"
StatusUnknown = "unknown"
StatusSucceeded = "succeeded"
StatusCanceled = "canceled"
StatusFailed = "failed"
StatusRunning = "running"
StatusPending = "pending"
StatusUnknown = "unknown"

// Deprecated: StatusSuccess has been replaced by StatusSucceeded.
StatusSuccess = StatusSucceeded

// Deprecated: StatusFailure has been replaced by StatusFailed.
StatusFailure = StatusFailed
)

// Action constants define the CNAB action to be taken
Expand Down Expand Up @@ -103,7 +111,7 @@ func (r Result) Validate() error {
}

switch r.Status {
case StatusFailure, StatusPending, StatusSuccess, StatusUnknown:
case StatusCanceled, StatusFailed, StatusPending, StatusRunning, StatusSucceeded, StatusUnknown:
return nil
}
return fmt.Errorf("invalid status: %s", r.Status)
Expand Down
27 changes: 24 additions & 3 deletions claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestUpdate(t *testing.T) {

time.Sleep(1 * time.Millisecond) // Force the Update to happen at a new time. For those of us who remembered to press the Turbo button.

claim.Update(ActionInstall, StatusSuccess)
claim.Update(ActionInstall, StatusSucceeded)

is := assert.New(t)
is.NotEqual(oldMod, claim.Modified)
is.NotEqual(oldUlid, claim.Revision)
is.Equal("install", claim.Result.Action)
is.Equal("success", claim.Result.Status)
is.Equal("succeeded", claim.Result.Status)
}

func TestValidName(t *testing.T) {
Expand Down Expand Up @@ -136,6 +136,27 @@ func TestValidateExampleClaim(t *testing.T) {
`claim validation failed: invalid schema version "not-semver": Invalid Semantic Version`)
}

func TestResult_Validate_ValidStatus(t *testing.T) {
validStatuses := []string{
StatusCanceled,
StatusRunning,
StatusFailed,
StatusPending,
StatusSucceeded,
StatusUnknown,
}
for _, status := range validStatuses {
t.Run(status+" status", func(t *testing.T) {
result := Result{
Action: ActionInstall,
Status: status,
}
err := result.Validate()
assert.NoError(t, err, "%s is a valid claim status", status)
})
}
}

func TestValidate_InvalidResult(t *testing.T) {
claim := exampleClaim

Expand All @@ -147,7 +168,7 @@ func TestValidate_InvalidResult(t *testing.T) {

t.Run("if result has empty action, validation should fail", func(t *testing.T) {
claim.Result = Result{
Status: StatusSuccess,
Status: StatusSucceeded,
}
err := claim.Validate()
assert.EqualError(t, err, "claim validation failed: the action must be provided")
Expand Down
2 changes: 1 addition & 1 deletion claim/claimstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCanUpdate(t *testing.T) {
require.NoError(t, err)

time.Sleep(1 * time.Millisecond)
claim.Update(ActionInstall, StatusSuccess)
claim.Update(ActionInstall, StatusSucceeded)

err = store.Save(*claim)
is.NoError(err, "Failed to update")
Expand Down

0 comments on commit 84c6ba8

Please sign in to comment.