2011-06-15 20:25:01 -04:00
|
|
|
Shindo.tests('Fog::DNS[:dnsimple] | DNS requests', ['dnsimple', 'dns']) do
|
2011-02-23 22:35:05 -05:00
|
|
|
|
2013-07-28 14:07:29 -04:00
|
|
|
@domain = nil
|
2011-02-23 22:35:05 -05:00
|
|
|
@domain_count = 0
|
|
|
|
|
2011-02-24 18:22:38 -05:00
|
|
|
tests("success") do
|
2011-02-23 22:35:05 -05:00
|
|
|
|
2011-02-24 18:22:38 -05:00
|
|
|
test("get current domain count") do
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].list_domains()
|
2011-02-23 22:35:05 -05:00
|
|
|
if response.status == 200
|
|
|
|
@domain_count = response.body.size
|
|
|
|
end
|
|
|
|
|
|
|
|
response.status == 200
|
|
|
|
end
|
|
|
|
|
2011-02-24 18:22:38 -05:00
|
|
|
test("create domain") do
|
2011-02-23 22:35:05 -05:00
|
|
|
domain = generate_unique_domain
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].create_domain(domain)
|
2011-02-23 22:35:05 -05:00
|
|
|
if response.status == 201
|
2011-02-24 00:56:16 -05:00
|
|
|
@domain = response.body["domain"]
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
response.status == 201
|
|
|
|
end
|
|
|
|
|
2011-02-24 00:56:16 -05:00
|
|
|
test("get domain by id") do
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].get_domain(@domain["id"])
|
2011-02-23 22:35:05 -05:00
|
|
|
response.status == 200
|
|
|
|
end
|
|
|
|
|
2011-02-24 00:56:16 -05:00
|
|
|
test("create an A resource record") do
|
|
|
|
domain = @domain["name"]
|
|
|
|
name = "www"
|
|
|
|
type = "A"
|
|
|
|
content = "1.2.3.4"
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].create_record(domain, name, type, content)
|
2011-02-23 22:35:05 -05:00
|
|
|
|
2011-02-24 00:56:16 -05:00
|
|
|
if response.status == 201
|
2011-02-24 18:22:38 -05:00
|
|
|
@record = response.body["record"]
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
2011-02-24 00:56:16 -05:00
|
|
|
response.status == 201
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-02-24 18:22:38 -05:00
|
|
|
test("create a MX record") do
|
|
|
|
domain = @domain["name"]
|
|
|
|
name = ""
|
|
|
|
type = "MX"
|
|
|
|
content = "mail.#{domain}"
|
2013-07-28 14:07:29 -04:00
|
|
|
options = { "ttl" => 60, "prio" => 10 }
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].create_record(domain, name, type, content, options)
|
2011-02-24 18:22:38 -05:00
|
|
|
|
2013-07-28 14:07:29 -04:00
|
|
|
test "MX record creation returns 201" do
|
|
|
|
response.status == 201
|
|
|
|
end
|
|
|
|
|
|
|
|
options.each do |key, value|
|
|
|
|
test("MX record has option #{key}") { value == response.body["record"][key.to_s] }
|
|
|
|
end
|
|
|
|
|
|
|
|
test "MX record is correct type" do
|
|
|
|
response.body["record"]["record_type"] == "MX"
|
|
|
|
end
|
2011-02-24 18:22:38 -05:00
|
|
|
end
|
|
|
|
|
2013-07-28 15:19:15 -04:00
|
|
|
test("get a record") do
|
|
|
|
domain = @domain["name"]
|
|
|
|
record_id = @record["id"]
|
|
|
|
|
|
|
|
response = Fog::DNS[:dnsimple].get_record(domain, record_id)
|
|
|
|
|
|
|
|
(response.status == 200) and (@record == response.body["record"])
|
|
|
|
end
|
|
|
|
|
2011-02-24 18:22:38 -05:00
|
|
|
test("update a record") do
|
|
|
|
domain = @domain["name"]
|
|
|
|
record_id = @record["id"]
|
2013-07-28 14:07:29 -04:00
|
|
|
options = { "content" => "2.3.4.5", "ttl" => 600 }
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].update_record(domain, record_id, options)
|
2011-02-24 18:22:38 -05:00
|
|
|
response.status == 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test("list records") do
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].list_records(@domain["name"])
|
2011-02-24 18:22:38 -05:00
|
|
|
|
|
|
|
if response.status == 200
|
|
|
|
@records = response.body
|
|
|
|
end
|
|
|
|
|
2013-07-28 14:07:29 -04:00
|
|
|
test "list records returns all records for domain" do
|
|
|
|
@records.reject { |record| record["record"]["system_record"] }.size == 2
|
|
|
|
end
|
|
|
|
|
|
|
|
response.status == 200
|
2011-02-24 18:22:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test("delete records") do
|
|
|
|
domain = @domain["name"]
|
|
|
|
|
|
|
|
result = true
|
|
|
|
@records.each do |record|
|
2013-07-28 14:07:29 -04:00
|
|
|
next if record["record"]["system_record"]
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].delete_record(domain, record["record"]["id"])
|
2013-07-28 14:07:29 -04:00
|
|
|
if response.status != 200
|
2011-02-24 18:22:38 -05:00
|
|
|
result = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2011-02-24 00:56:16 -05:00
|
|
|
test("delete domain") do
|
2011-06-15 20:25:01 -04:00
|
|
|
response = Fog::DNS[:dnsimple].delete_domain(@domain["name"])
|
2011-02-24 00:56:16 -05:00
|
|
|
response.status == 200
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|