From 87c4afcdd2693f5eb2f27e9c3682536e76c57515 Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Mon, 21 Jan 2013 21:39:24 +0100 Subject: [PATCH] [dreamhost|dns] refactor dns requests tests Every request now has it's own test file. --- .../requests/dns/create_record_tests.rb | 39 ++++++ .../requests/dns/delete_record_tests.rb | 26 ++++ tests/dreamhost/requests/dns/dns_tests.rb | 120 ------------------ .../requests/dns/list_records_tests.rb | 31 +++++ 4 files changed, 96 insertions(+), 120 deletions(-) create mode 100644 tests/dreamhost/requests/dns/create_record_tests.rb create mode 100644 tests/dreamhost/requests/dns/delete_record_tests.rb delete mode 100644 tests/dreamhost/requests/dns/dns_tests.rb create mode 100644 tests/dreamhost/requests/dns/list_records_tests.rb diff --git a/tests/dreamhost/requests/dns/create_record_tests.rb b/tests/dreamhost/requests/dns/create_record_tests.rb new file mode 100644 index 000000000..ab15f25bd --- /dev/null +++ b/tests/dreamhost/requests/dns/create_record_tests.rb @@ -0,0 +1,39 @@ +Shindo.tests('Fog::DNS[:dreamhost] | create_record request', ['dreamhost', 'dns']) do + + tests("success") do + + test("create an A resource record without comment") do + name = "foo.testing.#{test_domain}" + type = "A" + value = "1.2.3.4" + response = Fog::DNS[:dreamhost].create_record(name, type, value) + + response.body['result'] == 'success' + end + + test("create an A resource record with comment") do + name = "foo2.testing.#{test_domain}" + type = "A" + value = "1.2.3.4" + comment = "test" + response = Fog::DNS[:dreamhost].create_record(name, type, value, comment) + + response.body['result'] == 'success' + end + + test("create TXT record") do + name = "txt.testing.#{test_domain}" + type = "txt" + value = "foobar" + comment = "test" + response = Fog::DNS[:dreamhost].create_record(name, type, value, comment) + + response.body['result'] == 'success' + end + + end + + # helper + cleanup_records + +end diff --git a/tests/dreamhost/requests/dns/delete_record_tests.rb b/tests/dreamhost/requests/dns/delete_record_tests.rb new file mode 100644 index 000000000..0f8b82afa --- /dev/null +++ b/tests/dreamhost/requests/dns/delete_record_tests.rb @@ -0,0 +1,26 @@ +Shindo.tests('Fog::DNS[:dreamhost] | delete_record request', ['dreamhost', 'dns']) do + + tests("success") do + + test("delete testing records") do + name = "delete-test.#{test_domain}" + type = "A" + value = "1.2.3.4" + comment = "test" + Fog::DNS[:dreamhost].create_record(name, type, value, comment) + response = Fog::DNS[:dreamhost].delete_record(name, type, value) + response.body['result'] == 'success' + end + + end + + tests( 'failure') do + raises(RuntimeError, 'deleting non-existent record') do + Fog::DNS[:dreamhost].delete_record('foo.bar.bar', 'A', '1.2.3.4') + end + end + + # helper + cleanup_records + +end diff --git a/tests/dreamhost/requests/dns/dns_tests.rb b/tests/dreamhost/requests/dns/dns_tests.rb deleted file mode 100644 index 26669d182..000000000 --- a/tests/dreamhost/requests/dns/dns_tests.rb +++ /dev/null @@ -1,120 +0,0 @@ -Shindo.tests('Fog::DNS[:dreamhost] | DNS requests', ['dreamhost', 'dns']) do - - # Create some domains for testing - %w{one two three}.each do |dom| - name = "#{dom}.#{test_domain}" - type = "A" - value = "1.2.3.4" - comment = "test" - response = Fog::DNS[:dreamhost].create_record(name, type, value, comment) - end - - tests("success") do - - test("list records") do - pending if Fog.mocking? - - response = Fog::DNS[:dreamhost].list_records - - if response.status == 200 - @records = response.body["data"] - end - - (response.status == 200) and (response.body.size == 2) - end - - test("list all the records") do - pending if Fog.mocking? - - Fog::DNS[:dreamhost].records.all.size > 0 - end - - test("list records from existing zone") do - pending if Fog.mocking? - - Fog::DNS[:dreamhost].records.all(:zone => "#{test_domain}").size > 0 - end - - test("list records from nonexistent zone") do - pending if Fog.mocking? - - Fog::DNS[:dreamhost].records.all(:zone => 'foozoone.local').size == 0 - end - - test("create an A resource record without comment") do - pending if Fog.mocking? - - name = "foo.testing.#{test_domain}" - type = "A" - value = "1.2.3.4" - response = Fog::DNS[:dreamhost].create_record(name, type, value) - - response.body['result'] == 'success' - end - - test("create an A resource record with comment") do - pending if Fog.mocking? - - name = "foo2.testing.#{test_domain}" - type = "A" - value = "1.2.3.4" - comment = "test" - response = Fog::DNS[:dreamhost].create_record(name, type, value, comment) - - response.body['result'] == 'success' - end - - test("create TXT record") do - pending if Fog.mocking? - - name = "txt.testing.#{test_domain}" - type = "txt" - value = "foobar" - comment = "test" - response = Fog::DNS[:dreamhost].create_record(name, type, value, comment) - - response.body['result'] == 'success' - end - - test("TXT record found") do - pending if Fog.mocking? - - rec = Fog::DNS[:dreamhost].records.get "txt.testing.#{test_domain}" - - rec != nil - end - - test("delete testing records") do - pending if Fog.mocking? - - sleep 5 - - success = true - r = %w( - foo.testing.#{test_domain} - foo2.testing.#{test_domain} - txt.testing.#{test_domain} - ) - r.each do |rec| - name = rec - @records.each do |record| - if record['record'] == name - response = Fog::DNS[:dreamhost].delete_record(name, record["type"], record["value"]) - success = false if (response.body['result'] != 'success') - end - end - end - - success - end - - - end - - tests( 'failure') do - end - - # helper - cleanup_records - -end diff --git a/tests/dreamhost/requests/dns/list_records_tests.rb b/tests/dreamhost/requests/dns/list_records_tests.rb new file mode 100644 index 000000000..0c48270d8 --- /dev/null +++ b/tests/dreamhost/requests/dns/list_records_tests.rb @@ -0,0 +1,31 @@ +Shindo.tests('Fog::DNS[:dreamhost] | list_records request', ['dreamhost', 'dns']) do + + tests("success") do + + response = Fog::DNS[:dreamhost].list_records + + test("should return 200") do + if response.status == 200 + @records = response.body["data"] + end + (response.status == 200) and (response.body.size == 2) + end + + test("data should be an Array") do + @records.is_a? Array + end + + tests("should return records") do + %w{type zone value comment record}.each do |elem| + test("with #{elem}") do + @records.first[elem].is_a? String + end + end + end + + end + + # helper + cleanup_records + +end