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 /tests/spec | |
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
Diffstat (limited to 'tests/spec')
-rw-r--r-- | tests/spec/spec_helper.rb | 52 | ||||
-rw-r--r-- | tests/spec/validator.rb | 81 |
2 files changed, 133 insertions, 0 deletions
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 |