From 2ac385bbf1740cba6d47d9a9d16028c578a2fb36 Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Fri, 6 Apr 2012 17:45:11 -0400 Subject: [PATCH] Add tests for security group model and collection. --- .../hp/models/compute/security_group_tests.rb | 36 +++++++++++++++++++ .../models/compute/security_groups_tests.rb | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 tests/hp/models/compute/security_group_tests.rb create mode 100644 tests/hp/models/compute/security_groups_tests.rb diff --git a/tests/hp/models/compute/security_group_tests.rb b/tests/hp/models/compute/security_group_tests.rb new file mode 100644 index 000000000..6e4876fdf --- /dev/null +++ b/tests/hp/models/compute/security_group_tests.rb @@ -0,0 +1,36 @@ +Shindo.tests("Fog::Compute[:hp] | security_group", ['hp']) do + + model_tests(Fog::Compute[:hp].security_groups, {:name => 'foggroupname', :description => 'foggroupdescription'}, true) + + tests("a group with trailing whitespace") do + @group = Fog::Compute[:hp].security_groups.create(:name => "foggroup with spaces ", :description => " fog group desc ") + + test("name is correct") do + @group.name == "foggroup with spaces " + end + + test("description is correct") do + @group.description == " fog group desc " + end + + @other_group = Fog::Compute[:hp].security_groups.create(:name => 'other group', :description => 'another group') + + test("authorize access by another security group") do + sgrule = @group.create_rule(80..80, "tcp", nil, @other_group.id) + @sg_rule_id = sgrule.body['security_group_rule']['id'] + @group.reload + s = @group.rules.select {|r| r['id'] == @sg_rule_id unless r.nil?} + s[0]['id'] == @sg_rule_id + end + + test("revoke access from another security group") do + @group.delete_rule(@sg_rule_id) + @group.reload + s = @group.rules.select {|r| r['id'] == @sg_rule_id unless r.nil?} + s.empty? + end + + @other_group.destroy + @group.destroy + end +end diff --git a/tests/hp/models/compute/security_groups_tests.rb b/tests/hp/models/compute/security_groups_tests.rb new file mode 100644 index 000000000..bf9f7b151 --- /dev/null +++ b/tests/hp/models/compute/security_groups_tests.rb @@ -0,0 +1,5 @@ +Shindo.tests("Fog::Compute[:hp] | security_groups", ['hp']) do + + collection_tests(Fog::Compute[:hp].security_groups, {:name => 'foggroupname', :description => 'foggroupdescription'}, true) + +end