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

Show skip_message and correct title #1109

Merged
merged 2 commits into from
Sep 23, 2016
Merged

Show skip_message and correct title #1109

merged 2 commits into from
Sep 23, 2016

Conversation

alexpop
Copy link
Contributor

@alexpop alexpop commented Sep 20, 2016

Fixes: #1097

With the example in this ticket ^, the change in this PR provides the following output:

When a control title is not defined:

  ○  windows-4: Windows Feature 'linux_kernel'
     ○  The `windows_feature` resource is not supported on your OS.

When a control title is defined:

  ○  windows-4: Trying my luck :)
     ○  The `windows_feature` resource is not supported on your OS.

I'll have to do a bit more testing.

@ksubrama, do you recall why we have these?
https://github.com/chef/inspec/blob/v0.35.0/lib/inspec/rspec_json_formatter.rb#L337-L338

@alexpop
Copy link
Contributor Author

alexpop commented Sep 22, 2016

Tests still have to be updated, but let's agree on the desired format.

With this profile:

control 'CHECK file' do
  title "Check a file"
  describe file('/etc/passwd') do
    it { should exist }
    its('mode') { should cmp '0644' }
    its('size') { should be < 5 }
  end
end

control 'CHECK win111' do
  title "Trying my luck :)"
  describe windows_feature('linux_kernel') do
    it { should be_installed }
    its('info') { should cmp 'test' }
  end
end

control 'CHECK win222' do
  describe windows_feature('linux_kernel') do
    it { should be_installed }
  end
end

describe directory('/etc/') do
  it { should exist }
  its('mode') { should cmp '0755' }
end

describe windows_feature('linux_kernel') do
  it { should be_installed }
  it { should be_enabled }
end

Code in master is generating this cli output:

[12:15:13 ~/git/inspec (master)]$ be inspec exec /tmp/t.rb

Target:  local://

  ✖  CHECK file: Check a file (1 failed)
     ✖  File /etc/passwd size should be < 5
     expected: < 5
          got:   5253
     ✔  File /etc/passwd should exist
     ✔  File /etc/passwd mode should cmp "0644"
  ○  CHECK win111: Trying my luck :)
  ○  CHECK win222: Windows Feature 'linux_kernel' The `windows_feature` resource is not supported on your OS.

  File /etc/
     ✔  should exist
     ✔  mode should cmp "0755"
  Windows Feature
     ○  'linux_kernel' The `windows_feature` resource is not supported on your OS.

Profile Summary: 0 successful, 1 failures, 2 skipped
Test Summary: 4 successful, 1 failures, 3 skipped

As can be seen here(^), reason why control CHEF win111 skipped is not shown. Also, code description mesage is mixed with the skip message.

This is what my PR addresses and provides this output for the same profile:

[12:18:18 ~/git/inspec (ap/show-skip-message)]$ be inspec exec /tmp/t.rb

Target:  local://

  ✖  CHECK file: Check a file (1 failed)
     ✖  File /etc/passwd size should be < 5
     expected: < 5
          got:   5253
     ✔  File /etc/passwd should exist
     ✔  File /etc/passwd mode should cmp "0644"
  ○  CHECK win111: Trying my luck :)
     ○  The `windows_feature` resource is not supported on your OS.
  ○  CHECK win222: Windows Feature 'linux_kernel'
     ○  The `windows_feature` resource is not supported on your OS.

  File /etc/
     ✔  should exist
     ✔  mode should cmp "0755"
  Windows Feature
     ○  The `windows_feature` resource is not supported on your OS.

Profile Summary: 0 successful, 1 failures, 2 skipped
Test Summary: 4 successful, 1 failures, 3 skipped

It also removes the skip_message from code_desc when json formatting:

In master:

  "results": [
    {
      "status": "skipped",
      "code_desc": "Windows Feature 'linux_kernel' The `windows_feature` resource is not supported on your OS.",
      "skip_message": "The `windows_feature` resource is not supported on your OS.",
      "resource": "Windows Feature 'linux_kernel'",
      "run_time": 1.6e-05,
      "start_time": "2016-09-22 12:00:20 +0100"
    }

In ap/show-skip-message:

  "results": [
    {
      "status": "skipped",
      "code_desc": "Windows Feature 'linux_kernel'",
      "skip_message": "The `windows_feature` resource is not supported on your OS.",
      "resource": "Windows Feature 'linux_kernel'",
      "run_time": 9e-06,
      "start_time": "2016-09-22 11:58:11 +0100"
    }

@arlimus
Copy link
Contributor

arlimus commented Sep 22, 2016

I love that new output, it is much clearer and explains what is going on! Thank you Alex 👍

@chris-rock
Copy link
Contributor

👍

@alexpop alexpop changed the title WIP: Show skip_message and correct title Show skip_message and correct title Sep 22, 2016
@chris-rock
Copy link
Contributor

@alexpop is this ready? Could you please resolve the Gemfile conflict?

@alexpop
Copy link
Contributor Author

alexpop commented Sep 23, 2016

Ready @chris-rock, all green!

@chris-rock chris-rock merged commit 9334a4d into master Sep 23, 2016
@chris-rock chris-rock deleted the ap/show-skip-message branch September 23, 2016 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants