From 7e61b90d85544666c25333b2de6409f138503b33 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 21 Jan 2014 17:23:55 -0500 Subject: [PATCH] setting up testing library to start writing tests --- lib/fog/rage4/requests/dns/list_domains.rb | 2 +- tests/dns/helper.rb | 3 + tests/rage4/requests/dns/dns_tests.rb | 139 +++++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 tests/rage4/requests/dns/dns_tests.rb diff --git a/lib/fog/rage4/requests/dns/list_domains.rb b/lib/fog/rage4/requests/dns/list_domains.rb index 146b2e391..ac57b2ba1 100644 --- a/lib/fog/rage4/requests/dns/list_domains.rb +++ b/lib/fog/rage4/requests/dns/list_domains.rb @@ -3,7 +3,7 @@ module Fog class Rage4 class Real - # Get the details for all domains in your account. + # Get the lsit of all domains for your account. # ==== Parameters # # ==== Returns diff --git a/tests/dns/helper.rb b/tests/dns/helper.rb index bb0f1f98b..5bdf2ace6 100644 --- a/tests/dns/helper.rb +++ b/tests/dns/helper.rb @@ -35,6 +35,9 @@ def dns_providers :zone_attributes => { :email => 'fog@example.com' } + }, + :rage4 => { + :mocked => false, } } end diff --git a/tests/rage4/requests/dns/dns_tests.rb b/tests/rage4/requests/dns/dns_tests.rb new file mode 100644 index 000000000..9d9247b98 --- /dev/null +++ b/tests/rage4/requests/dns/dns_tests.rb @@ -0,0 +1,139 @@ +Shindo.tests('Fog::DNS[:rage4] | DNS requests', ['rage4', 'dns']) do + + @domain = '' + @domain_count = 0 + + tests("success") do + + test("get current domain count") do + pending if Fog.mocking? + + response = Fog::DNS[:rage4].list_domains() + debugger + if response.status == 200 + @domain_count = response.body['list'].size + end + + response.status == 200 + end + + test("create domain") do + pending if Fog.mocking? + + domain = generate_unique_domain + response = Fog::DNS[:rage4].create_domain(domain) + if response.status == 201 + @domain = response.body + end + + response.status == 201 + end + + test("get domain by name") do + pending if Fog.mocking? + + response = Fog::DNS[:rage4].get_domain(@domain["name"]) + response.status == 200 + end + + test("create an A resource record") do + pending if Fog.mocking? + + domain = @domain["name"] + name = "www" + type = "A" + data = "1.2.3.4" + response = Fog::DNS[:rage4].create_record(domain, name, type, data) + + if response.status == 201 + @record = response.body + end + + response.status == 201 + + end + + test("create a MX record") do + pending if Fog.mocking? + + domain = @domain["name"] + name = "" + type = "MX" + data = "10 mail.#{domain}" + options = { :ttl => 60 } + response = Fog::DNS[:rage4].create_record(domain, name, type, data, options) + + response.status == 201 + end + + test("update a record") do + pending if Fog.mocking? + + domain = @domain["name"] + record_id = @record["id"] + options = {:name => '', :type => 'A', :data => "2.3.4.5", :ttl => 600} + + response = Fog::DNS[:rage4].update_record(domain, record_id, options) + + response.status == 200 + end + + test("get record - check ip/ttl") do + pending if Fog.mocking? + + response = Fog::DNS[:rage4].get_record(@domain["name"], @record['id']) + record = response.body + result = false + + if response.status == 200 && record['data'] == '2.3.4.5' && record['ttl'] == 600 + result = true + end + + result + end + + test("list records") do + pending if Fog.mocking? + + response = Fog::DNS[:rage4].list_records(@domain["name"]) + + if response.status == 200 + @records = response.body + end + + (response.status == 200) and (response.body.size == 2) + end + + test("delete records") do + pending if Fog.mocking? + domain = @domain["name"] + + result = true + @records.each do |record| + response = Fog::DNS[:rage4].delete_record(domain, record["id"]) + if(response.status != 200) + result = false + break + end + end + + result + end + + test("delete domain") do + pending if Fog.mocking? + + #puts "Rage4 - Sleeping for 10 seconds, otherwise test fails because DNS Made Easy queues requests, it still might fail if DNS Made Easy is busy! MOCK IT!" + #puts "THIS MOST LIKELY WILL FAIL ON LIVE because it can take while for DNS Made Easy to create a domain/zone, changing the host to api.sandbox.rage4.com should make it work" + #sleep 10 + + response = Fog::DNS[:rage4].delete_domain(@domain["name"]) + response.status == 200 + end + + end + + tests( 'failure') do + end + +end