Skip to content

Commit

Permalink
Sync claim status names with the spec
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
carolynvs-msft committed Mar 4, 2020
1 parent ccc659c commit 377dbfe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 7 additions & 5 deletions claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ 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"
StatusSuccess = "succeeded"
StatusCanceled = "canceled"
StatusRunning = "running"
StatusFailure = "failed"
StatusPending = "pending"
StatusUnknown = "unknown"
)

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

switch r.Status {
case StatusFailure, StatusPending, StatusSuccess, StatusUnknown:
case StatusCanceled, StatusFailure, StatusPending, StatusRunning, StatusSuccess, StatusUnknown:
return nil
}
return fmt.Errorf("invalid status: %s", r.Status)
Expand Down
23 changes: 22 additions & 1 deletion claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestUpdate(t *testing.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,
StatusFailure,
StatusPending,
StatusSuccess,
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 Down

0 comments on commit 377dbfe

Please sign in to comment.