Merge pull request #1320 from chef/hannah-error-colors

Replaced Colors for output
This commit is contained in:
Dominik Richter 2016-11-23 20:29:42 -07:00 committed by GitHub
commit ae663708ce
2 changed files with 34 additions and 34 deletions

View file

@ -254,12 +254,12 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
}.freeze }.freeze
COLORS = { COLORS = {
'critical' => "\033[31;1m", 'critical' => "\033[38;5;9m",
'major' => "\033[31m", 'major' => "\033[38;5;208m",
'minor' => "\033[33m", 'minor' => "\033[0;36m",
'failed' => "\033[31m", 'failed' => "\033[38;5;9m",
'passed' => "\033[32m", 'passed' => "\033[38;5;41m",
'skipped' => "\033[37m", 'skipped' => "\033[38;5;247m",
'reset' => "\033[0m", 'reset' => "\033[0m",
}.freeze }.freeze

View file

@ -12,14 +12,14 @@ describe 'inspec exec' do
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
stdout = out.stdout.force_encoding(Encoding::UTF_8) stdout = out.stdout.force_encoding(Encoding::UTF_8)
stdout.must_include "\e[32m ✔ ssh-1: Allow only SSH Protocol 2\e[0m\n" stdout.must_include "\e[38;5;41m ✔ ssh-1: Allow only SSH Protocol 2\e[0m\n"
stdout.must_include "\e[32m ✔ tmp-1.0: Create /tmp directory\e[0m\n" stdout.must_include "\e[38;5;41m ✔ tmp-1.0: Create /tmp directory\e[0m\n"
stdout.must_include " stdout.must_include "
\e[37m gordon-1.0: Verify the version number of Gordon (1 skipped)\e[0m \e[38;5;247m gordon-1.0: Verify the version number of Gordon (1 skipped)\e[0m
\e[37m Can't find file \"/tmp/gordon/config.yaml\"\e[0m \e[38;5;247m Can't find file \"/tmp/gordon/config.yaml\"\e[0m
" "
stdout.must_include "\nProfile Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m1 skipped\e[0m" stdout.must_include "\nProfile Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m1 skipped\e[0m"
stdout.must_include "\nTest Summary: \e[32m4 successful\e[0m, \e[31m0 failures\e[0m, \e[37m1 skipped\e[0m\n" stdout.must_include "\nTest Summary: \e[38;5;41m4 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m1 skipped\e[0m\n"
end end
it 'executes a minimum metadata-only profile' do it 'executes a minimum metadata-only profile' do
@ -34,7 +34,7 @@ Target: local://
No tests executed.\e[0m No tests executed.\e[0m
Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m Test Summary: \e[38;5;41m0 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m
" "
end end
@ -50,7 +50,7 @@ Target: local://
No tests executed.\e[0m No tests executed.\e[0m
Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m Test Summary: \e[38;5;41m0 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m
" "
end end
@ -58,7 +58,7 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out = inspec("exec #{File.join(examples_path, 'profile-attribute')} --no-create-lockfile --attrs #{File.join(examples_path, "profile-attribute.yml")}") out = inspec("exec #{File.join(examples_path, 'profile-attribute')} --no-create-lockfile --attrs #{File.join(examples_path, "profile-attribute.yml")}")
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m"
end end
it 'executes a specs-only profile' do it 'executes a specs-only profile' do
@ -72,22 +72,22 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out.stdout.force_encoding(Encoding::UTF_8).must_include "↺ This will be skipped intentionally" out.stdout.force_encoding(Encoding::UTF_8).must_include "↺ This will be skipped intentionally"
out.stdout.force_encoding(Encoding::UTF_8).must_include "failing should" out.stdout.force_encoding(Encoding::UTF_8).must_include "failing should"
out.stdout.force_encoding(Encoding::UTF_8).must_include "∅ eq \"as intended\"" out.stdout.force_encoding(Encoding::UTF_8).must_include "∅ eq \"as intended\""
out.stdout.force_encoding(Encoding::UTF_8).must_include "Test Summary: \e[32m1 successful\e[0m, \e[31m1 failures\e[0m, \e[37m1 skipped\e[0m" out.stdout.force_encoding(Encoding::UTF_8).must_include "Test Summary: \e[38;5;41m1 successful\e[0m, \e[38;5;9m1 failures\e[0m, \e[38;5;247m1 skipped\e[0m"
end end
it 'executes only specified controls' do it 'executes only specified controls' do
out = inspec('exec ' + example_profile + ' --no-create-lockfile --controls tmp-1.0') out = inspec('exec ' + example_profile + ' --no-create-lockfile --controls tmp-1.0')
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.must_include "\nProfile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.must_include "\nProfile Summary: \e[38;5;41m1 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
it 'can execute a simple file with the default formatter' do it 'can execute a simple file with the default formatter' do
out = inspec('exec ' + example_control + ' --no-create-lockfile') out = inspec('exec ' + example_control + ' --no-create-lockfile')
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.must_include "\nProfile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.must_include "\nProfile Summary: \e[38;5;41m1 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
out.stdout.must_include "\nTest Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m" out.stdout.must_include "\nTest Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m"
end end
describe 'with a profile that is not supported on this OS/platform' do describe 'with a profile that is not supported on this OS/platform' do
@ -105,9 +105,9 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
let(:json) { JSON.load(out.stdout) } let(:json) { JSON.load(out.stdout) }
it 'exits with an error' do it 'exits with an error' do
out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy\e[0m\n\e[37m ↺ This will be skipped super intentionally.\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy\e[0m\n\e[38;5;247m ↺ This will be skipped super intentionally.\e[0m\n"
out.stdout.force_encoding(Encoding::UTF_8).must_include " ↺ CONTROL database: MySQL Session\e[0m\n\e[37m ↺ Can't run MySQL SQL checks without authentication\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include " ↺ CONTROL database: MySQL Session\e[0m\n\e[38;5;247m ↺ Can't run MySQL SQL checks without authentication\e[0m\n"
out.stdout.force_encoding(Encoding::UTF_8).must_include "Profile Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m2 skipped\e[0m" out.stdout.force_encoding(Encoding::UTF_8).must_include "Profile Summary: \e[38;5;41m0 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m2 skipped\e[0m"
out.exit_status.must_equal 0 out.exit_status.must_equal 0
end end
end end
@ -145,14 +145,14 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out.stdout.force_encoding(Encoding::UTF_8).must_equal " out.stdout.force_encoding(Encoding::UTF_8).must_equal "
Target: local:// Target: local://
\e[32m \xE2\x9C\x94 tmp-1.0: Create /tmp directory\e[0m \e[38;5;41m \xE2\x9C\x94 tmp-1.0: Create /tmp directory\e[0m
\e[32m \xE2\x9C\x94 File /tmp should be directory\e[0m \e[38;5;41m \xE2\x9C\x94 File /tmp should be directory\e[0m
File /tmp File /tmp
\e[32m \xE2\x9C\x94 should be directory\e[0m \e[38;5;41m \xE2\x9C\x94 should be directory\e[0m
Profile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m Profile Summary: \e[38;5;41m1 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m
Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m Test Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m
" "
end end
end end
@ -197,7 +197,7 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
let(:out) { inspec('exec ' + simple_inheritance) } let(:out) { inspec('exec ' + simple_inheritance) }
it 'should print the profile information and then the test results' do it 'should print the profile information and then the test results' do
out.stdout.force_encoding(Encoding::UTF_8).must_include "local://\n\n\n\e[31;1m × tmp-1.0: Create /tmp directory (1 failed)\e[0m\n\e[31;1m × File /tmp should not be directory\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "local://\n\n\n\e[38;5;9m × tmp-1.0: Create /tmp directory (1 failed)\e[0m\n\e[38;5;9m × File /tmp should not be directory\n"
end end
end end
@ -206,7 +206,7 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out = inspec('exec ' + File.join(profile_path, 'dependencies', 'resource-namespace') + ' --no-create-lockfile') out = inspec('exec ' + File.join(profile_path, 'dependencies', 'resource-namespace') + ' --no-create-lockfile')
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m5 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m5 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
end end
@ -215,7 +215,7 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out = inspec('exec ' + File.join(profile_path, 'dependencies', 'require_controls_test') + ' --no-create-lockfile') out = inspec('exec ' + File.join(profile_path, 'dependencies', 'require_controls_test') + ' --no-create-lockfile')
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m1 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
end end
@ -224,26 +224,26 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
out = inspec('exec ' + File.join(profile_path, 'dependencies', 'inheritance') + ' --no-create-lockfile') out = inspec('exec ' + File.join(profile_path, 'dependencies', 'inheritance') + ' --no-create-lockfile')
out.stderr.must_equal '' out.stderr.must_equal ''
out.exit_status.must_equal 0 out.exit_status.must_equal 0
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m6 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m6 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
end end
describe 'when using profiles on the supermarket' do describe 'when using profiles on the supermarket' do
it 'can run supermarket profiles directly from the command line' do it 'can run supermarket profiles directly from the command line' do
out = inspec("exec supermarket://nathenharvey/tmp-compliance-profile --no-create-lockfile") out = inspec("exec supermarket://nathenharvey/tmp-compliance-profile --no-create-lockfile")
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
it 'can run supermarket profiles from inspec.yml' do it 'can run supermarket profiles from inspec.yml' do
out = inspec("exec #{File.join(profile_path, 'supermarket-dep')} --no-create-lockfile") out = inspec("exec #{File.join(profile_path, 'supermarket-dep')} --no-create-lockfile")
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m2 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m0 skipped\e[0m\n"
end end
end end
describe 'when a dependency does not support our backend platform' do describe 'when a dependency does not support our backend platform' do
it 'skips the controls from that profile' do it 'skips the controls from that profile' do
out = inspec("exec #{File.join(profile_path, 'profile-support-skip')} --no-create-lockfile") out = inspec("exec #{File.join(profile_path, 'profile-support-skip')} --no-create-lockfile")
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m2 skipped\e[0m\n" out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[38;5;41m0 successful\e[0m, \e[38;5;9m0 failures\e[0m, \e[38;5;247m2 skipped\e[0m\n"
end end
end end
end end