Skip to content

Commit

Permalink
shell: non-0 exit code returns StatusWillChange
Browse files Browse the repository at this point in the history
fixes #323
  • Loading branch information
ryane committed Sep 28, 2016
1 parent 116ff1f commit 9256a60
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion resource/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func (s *Shell) StatusCode() resource.StatusLevel {
if s.Status == nil {
return resource.StatusFatal
}
return resource.StatusLevel(s.Status.ExitStatus)

if s.Status.ExitStatus == 0 {
return resource.StatusNoChange
}

return resource.StatusWillChange
}

// Messages returns a summary of the first execution of check and/or apply.
Expand Down
21 changes: 18 additions & 3 deletions resource/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,26 @@ func Test_StatusCode_WhenNoStatus_ReturnsFatal(t *testing.T) {
// TestStatusCodeWhenMultipleStatusReturnsMostRecentStatus tests what happens
// when there are multiple status returns
func TestStatusCodeWhenMultipleStatusReturnsMostRecentStatus(t *testing.T) {
var expected resource.StatusLevel = 7
// first result returns 0 (StatusNoChange)
status := &shell.CommandResults{ExitStatus: 0}
status = status.Cons("", &shell.CommandResults{ExitStatus: uint32(expected)})
// second result returns 7 (StatusWillChange)
status = status.Cons("", &shell.CommandResults{ExitStatus: 7})
sh := &shell.Shell{Status: status}
assert.Equal(t, expected, sh.StatusCode())
assert.Equal(t, resource.StatusWillChange, sh.StatusCode())
}

// TestStatusCodeWhenExitStatusZero verifies that StatusCode returns
// StatusNoChanges when a shell command has a zero exit code
func TestStatusCodeWhenExitStatusZero(t *testing.T) {
status := &shell.CommandResults{ExitStatus: 0}
sh := &shell.Shell{Status: status}
assert.Equal(t, resource.StatusNoChange, sh.StatusCode())
}

func TestStatusCodeWhenExitStatusNonZero(t *testing.T) {
status := &shell.CommandResults{ExitStatus: 4}
sh := &shell.Shell{Status: status}
assert.Equal(t, resource.StatusWillChange, sh.StatusCode())
}

// Shell context
Expand Down

0 comments on commit 9256a60

Please sign in to comment.