mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[dreamhost|dns] refactor dns requests tests
Every request now has it's own test file.
This commit is contained in:
parent
87d81967fa
commit
87c4afcdd2
4 changed files with 96 additions and 120 deletions
39
tests/dreamhost/requests/dns/create_record_tests.rb
Normal file
39
tests/dreamhost/requests/dns/create_record_tests.rb
Normal file
|
@ -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
|
26
tests/dreamhost/requests/dns/delete_record_tests.rb
Normal file
26
tests/dreamhost/requests/dns/delete_record_tests.rb
Normal file
|
@ -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
|
|
@ -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
|
31
tests/dreamhost/requests/dns/list_records_tests.rb
Normal file
31
tests/dreamhost/requests/dns/list_records_tests.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue