From ca1416fb0ad533e002ca2bee35edb3134f0155e0 Mon Sep 17 00:00:00 2001 From: Miah Johnson Date: Thu, 7 Nov 2019 15:42:48 -0800 Subject: [PATCH] Add some very basic tests. Several of which outright flunk! Signed-off-by: Miah Johnson --- test/artifact/artifact_helper.rb | 4 ++++ test/artifact/artifact_installation_test.rb | 21 +++++++++++++++++++++ test/artifact/inspec_archive_test.rb | 15 +++++++++++++++ test/artifact/inspec_check_test.rb | 15 +++++++++++++++ test/artifact/inspec_compliance_test.rb | 14 ++++++++++++++ test/artifact/inspec_env_test.rb | 14 ++++++++++++++ test/artifact/inspec_exec_test.rb | 15 +++++++++++++++ test/artifact/inspec_habitat_test.rb | 15 +++++++++++++++ test/artifact/inspec_help_test.rb | 14 ++++++++++++++ test/artifact/inspec_init_test.rb | 15 +++++++++++++++ test/artifact/inspec_json_test.rb | 17 +++++++++++++++++ test/artifact/inspec_plugin_test.rb | 15 +++++++++++++++ test/artifact/inspec_shell_test.rb | 14 ++++++++++++++ test/artifact/inspec_supermarket_test.rb | 15 +++++++++++++++ test/artifact/inspec_vendor_test.rb | 15 +++++++++++++++ test/artifact/inspec_version_test.rb | 14 ++++++++++++++ 16 files changed, 232 insertions(+) create mode 100644 test/artifact/artifact_helper.rb create mode 100644 test/artifact/artifact_installation_test.rb create mode 100644 test/artifact/inspec_archive_test.rb create mode 100644 test/artifact/inspec_check_test.rb create mode 100644 test/artifact/inspec_compliance_test.rb create mode 100644 test/artifact/inspec_env_test.rb create mode 100644 test/artifact/inspec_exec_test.rb create mode 100644 test/artifact/inspec_habitat_test.rb create mode 100644 test/artifact/inspec_help_test.rb create mode 100644 test/artifact/inspec_init_test.rb create mode 100644 test/artifact/inspec_json_test.rb create mode 100644 test/artifact/inspec_plugin_test.rb create mode 100644 test/artifact/inspec_shell_test.rb create mode 100644 test/artifact/inspec_supermarket_test.rb create mode 100644 test/artifact/inspec_vendor_test.rb create mode 100644 test/artifact/inspec_version_test.rb diff --git a/test/artifact/artifact_helper.rb b/test/artifact/artifact_helper.rb new file mode 100644 index 000000000..355f39359 --- /dev/null +++ b/test/artifact/artifact_helper.rb @@ -0,0 +1,4 @@ +require "minitest/autorun" +require "open3" + +TEST_CLI_OPTS="--chef-license=accept-no-persist" diff --git a/test/artifact/artifact_installation_test.rb b/test/artifact/artifact_installation_test.rb new file mode 100644 index 000000000..331e2aed1 --- /dev/null +++ b/test/artifact/artifact_installation_test.rb @@ -0,0 +1,21 @@ +require_relative "artifact_helper" + +class TestArtifactInstallation < Minitest::Test + parallelize_me! + + def test_inspec_exists_linux + skip if windows? + stdout, stderr, status = Open3.capture3("/usr/bin/which inspec") + refute_match(/no inspec/, stdout) + assert_empty stderr + assert status + end + + def test_inspec_exists_windows + skip unless windows? + stdout, stderr, status = Open3.capture3("Get-Command inspec") + assert_match(/inspec.bat/, stdout) + assert_empty stderr + assert status + end +end diff --git a/test/artifact/inspec_archive_test.rb b/test/artifact/inspec_archive_test.rb new file mode 100644 index 000000000..0424a0db8 --- /dev/null +++ b/test/artifact/inspec_archive_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecArchive < Minitest::Test + parallelize_me! + + def test_archive + flunk + command = "/bin/inspec archive #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert_match(/Platform Details/, stdout) + assert status + end +end diff --git a/test/artifact/inspec_check_test.rb b/test/artifact/inspec_check_test.rb new file mode 100644 index 000000000..749e02502 --- /dev/null +++ b/test/artifact/inspec_check_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecCheck < Minitest::Test + parallelize_me! + + def test_check + flunk + command = "/bin/inspec check #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert_match(/Platform Details/, stdout) + assert status + end +end diff --git a/test/artifact/inspec_compliance_test.rb b/test/artifact/inspec_compliance_test.rb new file mode 100644 index 000000000..cece32bb1 --- /dev/null +++ b/test/artifact/inspec_compliance_test.rb @@ -0,0 +1,14 @@ +require_relative "artifact_helper" + +class TestInspecCompliance < Minitest::Test + parallelize_me! + + def test_compliance_version + command = "/bin/inspec compliance version #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_env_test.rb b/test/artifact/inspec_env_test.rb new file mode 100644 index 000000000..424881a5e --- /dev/null +++ b/test/artifact/inspec_env_test.rb @@ -0,0 +1,14 @@ +require_relative "artifact_helper" +require "open3" + +class TestInspecEnv < Minitest::Test + parallelize_me! + def test_env + command = "/bin/inspec env #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_exec_test.rb b/test/artifact/inspec_exec_test.rb new file mode 100644 index 000000000..ea2a155b4 --- /dev/null +++ b/test/artifact/inspec_exec_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecExec < Minitest::Test + parallelize_me! + + def test_exec + flunk + command = "/bin/inspec exec #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_habitat_test.rb b/test/artifact/inspec_habitat_test.rb new file mode 100644 index 000000000..7963e2a3d --- /dev/null +++ b/test/artifact/inspec_habitat_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecHabitat < Minitest::Test + parallelize_me! + + def test_habitat + flunk + command = "/bin/inspec habitat #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_help_test.rb b/test/artifact/inspec_help_test.rb new file mode 100644 index 000000000..c7f9dac9e --- /dev/null +++ b/test/artifact/inspec_help_test.rb @@ -0,0 +1,14 @@ +require_relative "artifact_helper" +require "open3" + +class TestInspecHelp < Minitest::Test + parallelize_me! + def test_help + command = "/bin/inspec help #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_init_test.rb b/test/artifact/inspec_init_test.rb new file mode 100644 index 000000000..7c178e657 --- /dev/null +++ b/test/artifact/inspec_init_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecInit < Minitest::Test + parallelize_me! + + def test_init + flunk + command = "/bin/inspec init #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_json_test.rb b/test/artifact/inspec_json_test.rb new file mode 100644 index 000000000..ad1403a62 --- /dev/null +++ b/test/artifact/inspec_json_test.rb @@ -0,0 +1,17 @@ +require_relative "artifact_helper" +require "open3" + +class TestInspecJson < Minitest::Test + parallelize_me! + + def test_json + flunk + # Need a tempdir + command = "/bin/inspec json #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_plugin_test.rb b/test/artifact/inspec_plugin_test.rb new file mode 100644 index 000000000..b3815388e --- /dev/null +++ b/test/artifact/inspec_plugin_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecPlugin < Minitest::Test + parallelize_me! + + def test_plugin + flunk + command = "/bin/inspec plugin #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_shell_test.rb b/test/artifact/inspec_shell_test.rb new file mode 100644 index 000000000..b27279cb5 --- /dev/null +++ b/test/artifact/inspec_shell_test.rb @@ -0,0 +1,14 @@ +require_relative "artifact_helper" +require "open3" + +class TestInspecShell < Minitest::Test + parallelize_me! + def test_shell + command = "/bin/inspec shell -c 'os.family' #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_supermarket_test.rb b/test/artifact/inspec_supermarket_test.rb new file mode 100644 index 000000000..c4024ce3f --- /dev/null +++ b/test/artifact/inspec_supermarket_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecSupermarket < Minitest::Test + parallelize_me! + + def test_supermarket + flunk + command = "/bin/inspec supermarket #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_vendor_test.rb b/test/artifact/inspec_vendor_test.rb new file mode 100644 index 000000000..74daa9972 --- /dev/null +++ b/test/artifact/inspec_vendor_test.rb @@ -0,0 +1,15 @@ +require_relative "artifact_helper" + +class TestInspecVendor < Minitest::Test + parallelize_me! + + def test_vendor + flunk + command = "/bin/inspec vendor #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end diff --git a/test/artifact/inspec_version_test.rb b/test/artifact/inspec_version_test.rb new file mode 100644 index 000000000..19de98614 --- /dev/null +++ b/test/artifact/inspec_version_test.rb @@ -0,0 +1,14 @@ +require_relative "artifact_helper" +require "open3" + +class TestInspecVersion < Minitest::Test + parallelize_me! + def test_version + command = "/bin/inspec version #{TEST_CLI_OPTS}" + stdout, stderr, status = Open3.capture3(command) + + assert_empty stderr.sub(/#< CLIXML\n/, "") + assert stdout + assert status + end +end