diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-08 19:27:17 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-08 19:27:17 -0500 |
commit | 6d110a03892bf164826b27bd9f92ef396f36d1b3 (patch) | |
tree | 782695720242688b694e95a8c40dc708f5dfd6d3 | |
parent | e242f93977d28b8d645b53f28fe052071dcbf10d (diff) | |
download | horizon-6d110a03892bf164826b27bd9f92ef396f36d1b3.tar.gz horizon-6d110a03892bf164826b27bd9f92ef396f36d1b3.tar.bz2 horizon-6d110a03892bf164826b27bd9f92ef396f36d1b3.tar.xz horizon-6d110a03892bf164826b27bd9f92ef396f36d1b3.zip |
tests: Now with 100% more automated testing
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | tests/.rspec | 2 | ||||
-rw-r--r-- | tests/fixtures/0001-basic.installfile (renamed from tests/scripts/0001-basic.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0002-basic-commented.installfile (renamed from tests/scripts/0002-basic-commented.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0003-basic-whitespace.installfile (renamed from tests/scripts/0003-basic-whitespace.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0004-blank.installfile (renamed from tests/scripts/0004-blank.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0005-only-comments.installfile (renamed from tests/scripts/0005-only-comments.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0006-no-network.installfile (renamed from tests/scripts/0006-no-network.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0007-no-hostname.installfile (renamed from tests/scripts/0007-no-hostname.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0008-no-pkginstall.installfile (renamed from tests/scripts/0008-no-pkginstall.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0009-no-rootpw.installfile (renamed from tests/scripts/0009-no-rootpw.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0010-no-mount.installfile (renamed from tests/scripts/0010-no-mount.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0011-invalid-network.installfile (renamed from tests/scripts/0011-invalid-network.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0012-invalid-hostname.installfile (renamed from tests/scripts/0012-invalid-hostname.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0013-invalid-rootpw.installfile (renamed from tests/scripts/0013-invalid-rootpw.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0014-invalid-mount.installfile (renamed from tests/scripts/0014-invalid-mount.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0015-keys-without-values.installfile (renamed from tests/scripts/0015-keys-without-values.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0016-invalid-key.installfile (renamed from tests/scripts/0016-invalid-key.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0017-line-too-long.installfile (renamed from tests/scripts/0017-line-too-long.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0018-duplicate-network.installfile (renamed from tests/scripts/0018-duplicate-network.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0019-duplicate-hostname.installfile (renamed from tests/scripts/0019-duplicate-hostname.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0020-duplicate-rootpw.installfile (renamed from tests/scripts/0020-duplicate-rootpw.installfile) | 0 | ||||
-rw-r--r-- | tests/fixtures/0021-duplicate-root-mount.installfile (renamed from tests/scripts/0021-duplicate-root-mount.installfile) | 0 | ||||
-rw-r--r-- | tests/spec/spec_helper.rb | 52 | ||||
-rw-r--r-- | tests/spec/validator.rb | 81 |
25 files changed, 142 insertions, 0 deletions
@@ -1,4 +1,11 @@ +# Build artifacts build + +# Doc output devel/requirements/html devel/script/html devel/vision/html + +# RSpec +tests/spec/examples.txt +tests/tmp diff --git a/tests/.rspec b/tests/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/tests/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/tests/scripts/0001-basic.installfile b/tests/fixtures/0001-basic.installfile index a87b8f1..a87b8f1 100644 --- a/tests/scripts/0001-basic.installfile +++ b/tests/fixtures/0001-basic.installfile diff --git a/tests/scripts/0002-basic-commented.installfile b/tests/fixtures/0002-basic-commented.installfile index fd9a5e8..fd9a5e8 100644 --- a/tests/scripts/0002-basic-commented.installfile +++ b/tests/fixtures/0002-basic-commented.installfile diff --git a/tests/scripts/0003-basic-whitespace.installfile b/tests/fixtures/0003-basic-whitespace.installfile index 4754458..4754458 100644 --- a/tests/scripts/0003-basic-whitespace.installfile +++ b/tests/fixtures/0003-basic-whitespace.installfile diff --git a/tests/scripts/0004-blank.installfile b/tests/fixtures/0004-blank.installfile index e69de29..e69de29 100644 --- a/tests/scripts/0004-blank.installfile +++ b/tests/fixtures/0004-blank.installfile diff --git a/tests/scripts/0005-only-comments.installfile b/tests/fixtures/0005-only-comments.installfile index 72985bf..72985bf 100644 --- a/tests/scripts/0005-only-comments.installfile +++ b/tests/fixtures/0005-only-comments.installfile diff --git a/tests/scripts/0006-no-network.installfile b/tests/fixtures/0006-no-network.installfile index fcf0943..fcf0943 100644 --- a/tests/scripts/0006-no-network.installfile +++ b/tests/fixtures/0006-no-network.installfile diff --git a/tests/scripts/0007-no-hostname.installfile b/tests/fixtures/0007-no-hostname.installfile index 5e314e5..5e314e5 100644 --- a/tests/scripts/0007-no-hostname.installfile +++ b/tests/fixtures/0007-no-hostname.installfile diff --git a/tests/scripts/0008-no-pkginstall.installfile b/tests/fixtures/0008-no-pkginstall.installfile index 2751414..2751414 100644 --- a/tests/scripts/0008-no-pkginstall.installfile +++ b/tests/fixtures/0008-no-pkginstall.installfile diff --git a/tests/scripts/0009-no-rootpw.installfile b/tests/fixtures/0009-no-rootpw.installfile index d15d6b1..d15d6b1 100644 --- a/tests/scripts/0009-no-rootpw.installfile +++ b/tests/fixtures/0009-no-rootpw.installfile diff --git a/tests/scripts/0010-no-mount.installfile b/tests/fixtures/0010-no-mount.installfile index 99fc1da..99fc1da 100644 --- a/tests/scripts/0010-no-mount.installfile +++ b/tests/fixtures/0010-no-mount.installfile diff --git a/tests/scripts/0011-invalid-network.installfile b/tests/fixtures/0011-invalid-network.installfile index 77de188..77de188 100644 --- a/tests/scripts/0011-invalid-network.installfile +++ b/tests/fixtures/0011-invalid-network.installfile diff --git a/tests/scripts/0012-invalid-hostname.installfile b/tests/fixtures/0012-invalid-hostname.installfile index 6ea1fbc..6ea1fbc 100644 --- a/tests/scripts/0012-invalid-hostname.installfile +++ b/tests/fixtures/0012-invalid-hostname.installfile diff --git a/tests/scripts/0013-invalid-rootpw.installfile b/tests/fixtures/0013-invalid-rootpw.installfile index aeeda68..aeeda68 100644 --- a/tests/scripts/0013-invalid-rootpw.installfile +++ b/tests/fixtures/0013-invalid-rootpw.installfile diff --git a/tests/scripts/0014-invalid-mount.installfile b/tests/fixtures/0014-invalid-mount.installfile index cf3d44a..cf3d44a 100644 --- a/tests/scripts/0014-invalid-mount.installfile +++ b/tests/fixtures/0014-invalid-mount.installfile diff --git a/tests/scripts/0015-keys-without-values.installfile b/tests/fixtures/0015-keys-without-values.installfile index 7cb7aff..7cb7aff 100644 --- a/tests/scripts/0015-keys-without-values.installfile +++ b/tests/fixtures/0015-keys-without-values.installfile diff --git a/tests/scripts/0016-invalid-key.installfile b/tests/fixtures/0016-invalid-key.installfile index 9a7002e..9a7002e 100644 --- a/tests/scripts/0016-invalid-key.installfile +++ b/tests/fixtures/0016-invalid-key.installfile diff --git a/tests/scripts/0017-line-too-long.installfile b/tests/fixtures/0017-line-too-long.installfile index f208b5f..f208b5f 100644 --- a/tests/scripts/0017-line-too-long.installfile +++ b/tests/fixtures/0017-line-too-long.installfile diff --git a/tests/scripts/0018-duplicate-network.installfile b/tests/fixtures/0018-duplicate-network.installfile index bce490c..bce490c 100644 --- a/tests/scripts/0018-duplicate-network.installfile +++ b/tests/fixtures/0018-duplicate-network.installfile diff --git a/tests/scripts/0019-duplicate-hostname.installfile b/tests/fixtures/0019-duplicate-hostname.installfile index ae7f199..ae7f199 100644 --- a/tests/scripts/0019-duplicate-hostname.installfile +++ b/tests/fixtures/0019-duplicate-hostname.installfile diff --git a/tests/scripts/0020-duplicate-rootpw.installfile b/tests/fixtures/0020-duplicate-rootpw.installfile index c3727d2..c3727d2 100644 --- a/tests/scripts/0020-duplicate-rootpw.installfile +++ b/tests/fixtures/0020-duplicate-rootpw.installfile diff --git a/tests/scripts/0021-duplicate-root-mount.installfile b/tests/fixtures/0021-duplicate-root-mount.installfile index 0d009cd..0d009cd 100644 --- a/tests/scripts/0021-duplicate-root-mount.installfile +++ b/tests/fixtures/0021-duplicate-root-mount.installfile diff --git a/tests/spec/spec_helper.rb b/tests/spec/spec_helper.rb new file mode 100644 index 0000000..ab821ba --- /dev/null +++ b/tests/spec/spec_helper.rb @@ -0,0 +1,52 @@ +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. + config.example_status_persistence_file_path = "spec/examples.txt" + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +end diff --git a/tests/spec/validator.rb b/tests/spec/validator.rb new file mode 100644 index 0000000..69fe0d1 --- /dev/null +++ b/tests/spec/validator.rb @@ -0,0 +1,81 @@ +require 'aruba/rspec' + +IFILE_PATH = 'installfile' + +def run_validate(extra = '') + run_command 'hscript-validate ' + IFILE_PATH + extra +end + +def use_fixture(fixture) + copy '%/' + fixture, IFILE_PATH +end + +SUCCESS_OUTPUT = '0 error(s), 0 warning(s)' + +RSpec.describe 'HorizonScript Validation Utility', :type => :aruba do + context "argument passing" do + it "requires an installfile to be specified" do + run_command 'hscript-validate' + expect(last_command_started).to have_output(/usage/) + end + it "doesn't output ANSI colours when redirected" do + run_command 'hscript-validate foo 2>/dev/null' + expect(last_command_started).to_not have_output(/\033/) + end + end + context "on invalid keys" do + before(:each) { use_fixture '0016-invalid-key.installfile' } + it "warns on invalid keys by default" do + run_validate + expect(last_command_started).to have_output(/warning: .*chat.* not defined/) + end + it "errors on invalid keys in strict mode" do + run_validate ' --strict' + expect(last_command_started).to have_output(/error: .*chat.* not defined/) + end + end + context "parsing" do + it "successfully reads a basic installfile" do + use_fixture '0001-basic.installfile' + run_validate + expect(last_command_started).to have_output(SUCCESS_OUTPUT) + end + it "handles comments" do + use_fixture '0002-basic-commented.installfile' + run_validate + expect(last_command_started).to have_output(SUCCESS_OUTPUT) + end + it "handles blank lines and indentation" do + use_fixture '0003-basic-whitespace.installfile' + run_validate + expect(last_command_started).to have_output(SUCCESS_OUTPUT) + end + context "required keys" do + it "fails without a 'network' key" do + use_fixture '0006-no-network.installfile' + run_validate + expect(last_command_started).to have_output(/error: .*network.*/) + end + it "fails without a 'hostname' key" do + use_fixture '0007-no-hostname.installfile' + run_validate + expect(last_command_started).to have_output(/error: .*hostname.*/) + end + it "fails without a 'pkginstall' key" do + use_fixture '0008-no-pkginstall.installfile' + run_validate + expect(last_command_started).to have_output(/error: .*pkginstall.*/) + end + it "fails without a 'rootpw' key" do + use_fixture '0009-no-rootpw.installfile' + run_validate + expect(last_command_started).to have_output(/error: .*rootpw.*/) + end + it "fails without a 'mount' key" do + use_fixture '0010-no-mount.installfile' + run_validate + expect(last_command_started).to have_output(/error: .*mount.*/) + end + end + end +end |