From b52dc922f7c8c44d0560039a50bb51875cd25b1e Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Oct 2023 06:30:48 +0000 Subject: [PATCH] add specs for LibrarySourceConfig --- lib/bashly/library_source_config.rb | 2 +- .../libraries_validation/files_array | 1 + .../libraries_validation/files_source | 1 + .../libraries_validation/files_target | 1 + .../libraries_validation/handler_string | 1 + .../libraries_validation/help_string | 1 + .../libraries_validation/message_string | 1 + spec/approvals/libraries_validation/root_hash | 1 + .../libraries_validation/usage_string | 1 + spec/bashly/config_validator_spec.rb | 7 +++-- spec/bashly/library_source_config_spec.rb | 26 +++++++++++++++++++ .../libraries_validation/files_array.yml | 4 +++ .../libraries_validation/files_source.yml | 6 +++++ .../libraries_validation/files_target.yml | 6 +++++ .../libraries_validation/handler_string.yml | 7 +++++ .../libraries_validation/help_string.yml | 6 +++++ .../libraries_validation/message_string.yml | 7 +++++ .../libraries_validation/root_hash.yml | 6 +++++ .../libraries_validation/usage_string.yml | 7 +++++ 19 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 spec/approvals/libraries_validation/files_array create mode 100644 spec/approvals/libraries_validation/files_source create mode 100644 spec/approvals/libraries_validation/files_target create mode 100644 spec/approvals/libraries_validation/handler_string create mode 100644 spec/approvals/libraries_validation/help_string create mode 100644 spec/approvals/libraries_validation/message_string create mode 100644 spec/approvals/libraries_validation/root_hash create mode 100644 spec/approvals/libraries_validation/usage_string create mode 100644 spec/bashly/library_source_config_spec.rb create mode 100644 spec/fixtures/libraries_validation/files_array.yml create mode 100644 spec/fixtures/libraries_validation/files_source.yml create mode 100644 spec/fixtures/libraries_validation/files_target.yml create mode 100644 spec/fixtures/libraries_validation/handler_string.yml create mode 100644 spec/fixtures/libraries_validation/help_string.yml create mode 100644 spec/fixtures/libraries_validation/message_string.yml create mode 100644 spec/fixtures/libraries_validation/root_hash.yml create mode 100644 spec/fixtures/libraries_validation/usage_string.yml diff --git a/lib/bashly/library_source_config.rb b/lib/bashly/library_source_config.rb index 5dc78d58..53f381fa 100644 --- a/lib/bashly/library_source_config.rb +++ b/lib/bashly/library_source_config.rb @@ -30,7 +30,7 @@ def assert_root(path, value) def assert_lib(key, value) assert_string "#{key}.help", value['help'] - + assert_optional_string "#{key}.usage", value['usage'] assert_optional_string "#{key}.handler", value['handler'] assert_optional_string "#{key}.post_install_message", value['post_install_message'] diff --git a/spec/approvals/libraries_validation/files_array b/spec/approvals/libraries_validation/files_array new file mode 100644 index 00000000..f78264a3 --- /dev/null +++ b/spec/approvals/libraries_validation/files_array @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/files_source b/spec/approvals/libraries_validation/files_source new file mode 100644 index 00000000..21f98c90 --- /dev/null +++ b/spec/approvals/libraries_validation/files_source @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/files_target b/spec/approvals/libraries_validation/files_target new file mode 100644 index 00000000..67580069 --- /dev/null +++ b/spec/approvals/libraries_validation/files_target @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/handler_string b/spec/approvals/libraries_validation/handler_string new file mode 100644 index 00000000..4fb9d1db --- /dev/null +++ b/spec/approvals/libraries_validation/handler_string @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/help_string b/spec/approvals/libraries_validation/help_string new file mode 100644 index 00000000..8d40fb91 --- /dev/null +++ b/spec/approvals/libraries_validation/help_string @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/message_string b/spec/approvals/libraries_validation/message_string new file mode 100644 index 00000000..f9ecbea5 --- /dev/null +++ b/spec/approvals/libraries_validation/message_string @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/root_hash b/spec/approvals/libraries_validation/root_hash new file mode 100644 index 00000000..bf1c0a67 --- /dev/null +++ b/spec/approvals/libraries_validation/root_hash @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/libraries_validation/usage_string b/spec/approvals/libraries_validation/usage_string new file mode 100644 index 00000000..877e9c1e --- /dev/null +++ b/spec/approvals/libraries_validation/usage_string @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/bashly/config_validator_spec.rb b/spec/bashly/config_validator_spec.rb index 7e88096c..9d091fea 100644 --- a/spec/bashly/config_validator_spec.rb +++ b/spec/bashly/config_validator_spec.rb @@ -1,14 +1,13 @@ describe ConfigValidator do fixtures = load_fixture 'script/validations' - subject { described_class.new options } describe '#validate' do fixtures.each do |fixture, options| - context "with :#{fixture}" do - let(:options) { options } + validator = described_class.new options + context "with :#{fixture}" do it 'raises an error' do - expect { subject.validate }.to raise_approval("validations/#{fixture}") + expect { validator.validate }.to raise_approval("validations/#{fixture}") end end end diff --git a/spec/bashly/library_source_config_spec.rb b/spec/bashly/library_source_config_spec.rb new file mode 100644 index 00000000..9b4739e5 --- /dev/null +++ b/spec/bashly/library_source_config_spec.rb @@ -0,0 +1,26 @@ +describe LibrarySourceConfig do + fixtures = Dir['spec/fixtures/libraries_errors/*.yml'] + subject { described_class.new path } + + let(:path) { 'spec/fixtures/libraries/libraries.yml' } + + describe '#validated_data' do + it 'returns the data after validating it' do + expect(subject).to receive(:validate) + expect(subject.validated_data).to eq subject.data + end + end + + describe '#validate' do + fixtures.each do |path| + fixture_name = File.basename path, '.yml' + config = described_class.new path + + context "with #{fixture_name}.yml" do + it 'raises an error' do + expect { config.validate }.to raise_approval("libraries_validation/#{fixture_name}") + end + end + end + end +end diff --git a/spec/fixtures/libraries_validation/files_array.yml b/spec/fixtures/libraries_validation/files_array.yml new file mode 100644 index 00000000..998fd18c --- /dev/null +++ b/spec/fixtures/libraries_validation/files_array.yml @@ -0,0 +1,4 @@ +# error: files must be an array +database: + help: Help text + files: one_file.txt diff --git a/spec/fixtures/libraries_validation/files_source.yml b/spec/fixtures/libraries_validation/files_source.yml new file mode 100644 index 00000000..a1532f5d --- /dev/null +++ b/spec/fixtures/libraries_validation/files_source.yml @@ -0,0 +1,6 @@ +# error: files must have a source +database: + help: Help text + files: + - target: some_target + diff --git a/spec/fixtures/libraries_validation/files_target.yml b/spec/fixtures/libraries_validation/files_target.yml new file mode 100644 index 00000000..f690b7e9 --- /dev/null +++ b/spec/fixtures/libraries_validation/files_target.yml @@ -0,0 +1,6 @@ +# error: files must have a target +database: + help: Help text + files: + - source: some_source + diff --git a/spec/fixtures/libraries_validation/handler_string.yml b/spec/fixtures/libraries_validation/handler_string.yml new file mode 100644 index 00000000..85266e93 --- /dev/null +++ b/spec/fixtures/libraries_validation/handler_string.yml @@ -0,0 +1,7 @@ +# error: handler must be a string (optional) +database: + help: Help text + handler: 1 + files: + - source: "database/database.sh" + target: "%{user_lib_dir}/database.%{user_ext}" diff --git a/spec/fixtures/libraries_validation/help_string.yml b/spec/fixtures/libraries_validation/help_string.yml new file mode 100644 index 00000000..4d2ae109 --- /dev/null +++ b/spec/fixtures/libraries_validation/help_string.yml @@ -0,0 +1,6 @@ +# error: help must be a string +database: + help: 1 + files: + - source: "database/database.sh" + target: "%{user_lib_dir}/database.%{user_ext}" diff --git a/spec/fixtures/libraries_validation/message_string.yml b/spec/fixtures/libraries_validation/message_string.yml new file mode 100644 index 00000000..0ab1145d --- /dev/null +++ b/spec/fixtures/libraries_validation/message_string.yml @@ -0,0 +1,7 @@ +# error: post_install_message must be a string (optional) +database: + help: Help text + post_install_message: 1 + files: + - source: "database/database.sh" + target: "%{user_lib_dir}/database.%{user_ext}" diff --git a/spec/fixtures/libraries_validation/root_hash.yml b/spec/fixtures/libraries_validation/root_hash.yml new file mode 100644 index 00000000..374aae0a --- /dev/null +++ b/spec/fixtures/libraries_validation/root_hash.yml @@ -0,0 +1,6 @@ +# error: must be a hash +- database: + help: Add database utilities + files: + - source: "database/database.sh" + target: "%{user_lib_dir}/database.%{user_ext}" diff --git a/spec/fixtures/libraries_validation/usage_string.yml b/spec/fixtures/libraries_validation/usage_string.yml new file mode 100644 index 00000000..8e9207e4 --- /dev/null +++ b/spec/fixtures/libraries_validation/usage_string.yml @@ -0,0 +1,7 @@ +# error: usage must be a string (optional) +database: + help: Help text + usage: 1 + files: + - source: "database/database.sh" + target: "%{user_lib_dir}/database.%{user_ext}"