Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Refactor out the 'test_cases' array
Browse files Browse the repository at this point in the history
The test_cases array is not useful in the generators tests,
and has caused problems.

This refactors it into individual test cases, as per NatService
generator.
  • Loading branch information
mikepea committed Mar 6, 2014
1 parent 686aa89 commit 70d680c
Showing 1 changed file with 46 additions and 52 deletions.
Expand Up @@ -66,11 +66,8 @@ module ConfigurationGenerator

context "firewall config generation" do

test_cases = [

{
title: 'disabled firewall with a disabled rule',
input: {
it 'should have disabled firewall with a disabled rule' do
input = {
enabled: 'false',
policy: 'allow',
log_default_action: 'true',
Expand All @@ -89,8 +86,8 @@ module ConfigurationGenerator
enable_logging: 'true',
}
]
},
output: {
}
output = {
IsEnabled: 'false',
DefaultAction: "allow",
LogDefaultAction: 'true',
Expand All @@ -111,12 +108,13 @@ module ConfigurationGenerator
EnableLogging: 'true',
}
]
}
},
}
generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

{
title: 'id should be auto generated if not provided',
input: {
it 'id should be auto generated if not provided' do
input = {
firewall_rules: [
{
description: "rule 1",
Expand All @@ -131,8 +129,8 @@ module ConfigurationGenerator
source_ip: "192.0.2.2",
}
]
},
output: {
}
output = {
IsEnabled: 'true',
DefaultAction: "drop",
LogDefaultAction: 'false',
Expand Down Expand Up @@ -168,12 +166,13 @@ module ConfigurationGenerator
EnableLogging: 'false',
}
]
}
},
}
generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

{
title: 'should send port as -1 if destination/source_port_ranges are ranges',
input: {
it 'should send port as -1 if destination/source_port_ranges are ranges' do
input = {
firewall_rules: [
{
description: "rule 1",
Expand All @@ -183,8 +182,8 @@ module ConfigurationGenerator
source_ip: "192.0.2.2",
}
]
},
output: {
}
output = {
IsEnabled: 'true',
DefaultAction: "drop",
LogDefaultAction: 'false',
Expand All @@ -205,12 +204,13 @@ module ConfigurationGenerator
EnableLogging: 'false',
}
]
}
},
}
generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

{
title: 'should send port same as destination/source_port_range if destination/source_port_range are decimals and not ranges',
input: {
it 'should send port same as destination/source_port_range if destination/source_port_range are decimals and not ranges' do
input = {
firewall_rules: [
{
description: "rule 1",
Expand All @@ -220,8 +220,8 @@ module ConfigurationGenerator
source_ip: "192.0.2.2",
}
]
},
output: {
}
output = {
IsEnabled: 'true',
DefaultAction: "drop",
LogDefaultAction: 'false',
Expand All @@ -242,12 +242,13 @@ module ConfigurationGenerator
EnableLogging: 'false',
}
]
},
},
}
generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

{
title: 'should handle a rule specifiying "any" protocols',
input: {
it 'should handle a rule specifiying "any" protocols' do
input = {
firewall_rules: [
{
description: "allow any protocol",
Expand All @@ -256,8 +257,8 @@ module ConfigurationGenerator
source_ip: "192.0.2.2",
}
]
},
output: {
}
output = {
IsEnabled: 'true',
DefaultAction: "drop",
LogDefaultAction: 'false',
Expand All @@ -278,12 +279,13 @@ module ConfigurationGenerator
EnableLogging: 'false',
}
]
},
},
}
generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

{
title: 'output rule order should be same as the input rule order',
input: {
it 'output rule order should be same as the input rule order' do
input = {
firewall_rules: [
{
description: "rule 1",
Expand Down Expand Up @@ -316,8 +318,8 @@ module ConfigurationGenerator
source_ip: "Any",
},
],
},
output: {
}
output = {
IsEnabled: 'true',
DefaultAction: "drop",
LogDefaultAction: 'false',
Expand Down Expand Up @@ -398,17 +400,9 @@ module ConfigurationGenerator
EnableLogging: 'false',
}
]
}
}

]

test_cases.each do |test_case|
it "#{test_case[:title]}" do
generated_config = FirewallService.new.generate_fog_config test_case[:input]
expect(generated_config).to eq(test_case[:output])
end

generated_config = FirewallService.new.generate_fog_config(input)
expect(generated_config).to eq(output)
end

end
Expand Down

0 comments on commit 70d680c

Please sign in to comment.