Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: non-0 exit code returns StatusWillChange #324

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 20 additions & 3 deletions resource/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,28 @@ 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())
}

// TestStatusCodeWhenExitStatusNonZero verifies that StatusCode returns
// StatusWillChange when a shell command has a non-zero exit code
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