Commit 1ff4506d authored by Rich's avatar Rich
Browse files

Finish variables specs

parent b5052acf
......@@ -36,6 +36,22 @@ end
###############################################################################
shared_examples "variables adding valid hash" do |name|
describe "passing #{name} variables hash" do
it "must add and process valid variables" do
begin
variables.add_variables(variables: hash)
rescue SystemExit => e
raise "Test failed!"
end
expect(variables.values[key]).to eql(value)
end
end
end
###############################################################################
shared_examples "variables identifier is set and has correct value" do |name|
it "#{name}" do
expect(variables.identifiers[name.to_sym]).to eql(value)
......@@ -84,8 +100,13 @@ describe TerraformWrapper::Shared::Variables do
@identifiers_valid = { "network" => "testnet", "account" => "testing", "CASE" => @identifiers_case_value }
@variables_invalid_array = Array.new
@variables_invalid_blank = { "blank" => "" }
@variables_invalid_key = { Hash.new => "value" }
@variables_invalid_string = "invalid"
@variables_invalid_identifier = { "bucket" => "%{stream}" }
@variables_invalid_value_type = { "array" => Array.new }
@variables_valid_stripping = { "space" => " test " }
@variables_valid_templating = { "group" => "%{case}-group", "before" => "before" }
end
it_behaves_like "variables with invalid identifiers", "nil" do
......@@ -221,17 +242,83 @@ describe TerraformWrapper::Shared::Variables do
let(:hash) { @variables_invalid_string }
end
it_behaves_like "variables adding invalid hash", "array variable" do
let(:hash) { @variables_invalid_value_type }
end
it_behaves_like "variables adding invalid hash", "blank variable" do
let(:hash) { @variables_invalid_blank }
end
it_behaves_like "variables adding invalid hash", "hash key" do
let(:hash) { @variables_invalid_key }
end
it_behaves_like "variables adding invalid hash", "templated identifer that does not exist" do
let(:hash) { @variables_invalid_identifier }
end
# duplicates (seperate and together)
# sorting
# succuessful templating
# stripping?
# invalid key
# invalid/blank value
it_behaves_like "variables adding valid hash", "stripped" do
let(:hash) { @variables_valid_stripping }
let(:key) { :space }
let(:value) { "test" }
end
it_behaves_like "variables adding valid hash", "templated" do
let(:hash) { @variables_valid_templating }
let(:key) { :group }
let(:value) { "#{@identifiers_case_value}-group" }
end
describe "fail adding duplicate variables" do
it "must succeed first time, fail second time" do
begin
variables.add_variables(variables: @variables_valid_stripping)
rescue SystemExit => e
raise "Test failed!"
end
expect { variables.add_variables(variables: @variables_valid_stripping) }.to raise_error(SystemExit)
end
it "must succeed first time, have error code 1 second time" do
begin
variables.add_variables(variables: @variables_valid_stripping)
rescue SystemExit => e
raise "Test failed!"
end
begin
variables.add_variables(variables: @variables_valid_stripping)
rescue SystemExit => e
expect(e.status).to eq(1)
end
end
end
describe "variables added with sorting" do
it "must have the variables returned in the same order that they were provided" do
begin
variables.add_variables(variables: @variables_valid_templating, sort: true)
rescue SystemExit => e
raise "Test failed!"
end
expect(variables.values.find_index { |k,_| k == :group }).to be > variables.values.find_index { |k,_| k == :before }
end
end
describe "variables added unsorted" do
it "must have the variables returned in the same order that they were provided" do
begin
variables.add_variables(variables: @variables_valid_templating)
rescue SystemExit => e
raise "Test failed!"
end
expect(variables.values.find_index { |k,_| k == :before }).to be > variables.values.find_index { |k,_| k == :group }
end
end
end
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment