summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Alves <diego.oborba@gmail.com>2016-08-19 13:33:50 -0300
committerDiego Alves <diego.oborba@gmail.com>2016-08-19 16:45:51 -0300
commit099b410a51a595dca6ef86468f7b9489ecaa60ef (patch)
treefd70caed1308864436d4852445fa4f4e300fa8e8 /test
parentMerge branch 'WIP' into delete_zone (diff)
parentAdd tests to uptade Record (diff)
merge master conflicts
Diffstat (limited to 'test')
-rw-r--r--test/lib/powerdnsex/managers/records_manager_test.exs32
-rw-r--r--test/lib/powerdnsex/managers/zones_manager_test.exs6
-rw-r--r--test/support/cassettes/records_manager/update/invalid_record.json31
-rw-r--r--test/support/cassettes/records_manager/update/not_found.json31
-rw-r--r--test/support/cassettes/zones_manager/delete/not_found.json4
-rw-r--r--test/support/cassettes/zones_manager/delete/success.json2
6 files changed, 100 insertions, 6 deletions
diff --git a/test/lib/powerdnsex/managers/records_manager_test.exs b/test/lib/powerdnsex/managers/records_manager_test.exs
index 3b91fc2..5f314bd 100644
--- a/test/lib/powerdnsex/managers/records_manager_test.exs
+++ b/test/lib/powerdnsex/managers/records_manager_test.exs
@@ -25,6 +25,18 @@ defmodule PowerDNSex.RecordsManagerTest do
records: [{"127.0.0.1", true}]
}
+ @invalid_record %{
+ name: "updated-record.my-domain.art.",
+ type: "NS",
+ ttl: 86800,
+ records: [{"127.0.0.1", true}]
+ }
+
+ @invalid_zone %Zone{
+ name: "not-canonical-domain.tst",
+ url: "api/v1/servers/localhost/zones/not-canonical-domain.tst"
+ }
+
setup do
# Config.set_url
# Config.set_token
@@ -64,10 +76,30 @@ defmodule PowerDNSex.RecordsManagerTest do
end
end
+ @tag :records_manager_update
test "the return given correct params" do
use_cassette "records_manager/update/success" do
assert RecordsManager.update(@valid_zone, @updated_record) == :ok
end
end
+
+ @tag :records_manager_update
+ test "the return given incorrect zone" do
+ use_cassette "records_manager/update/not_found" do
+ response = RecordsManager.update(@invalid_zone, @updated_record)
+ error_msg = "Could not find domain '#{@invalid_zone.name}.'"
+ assert response.error == error_msg
+ end
+ end
+
+ @tag :records_manager_update
+ test "the return given incorrect params" do
+ use_cassette "records_manager/update/invalid_record" do
+ response = RecordsManager.update(@valid_zone, @invalid_record)
+ error_msg = "Record updated-record.my-domain.art./NS '127.0.0.1': " <>
+ "Not in expected format (parsed as '127.0.0.1.')"
+ assert response.error == error_msg
+ end
+ end
end
end
diff --git a/test/lib/powerdnsex/managers/zones_manager_test.exs b/test/lib/powerdnsex/managers/zones_manager_test.exs
index 2e88c70..b3aa5ef 100644
--- a/test/lib/powerdnsex/managers/zones_manager_test.exs
+++ b/test/lib/powerdnsex/managers/zones_manager_test.exs
@@ -104,15 +104,15 @@ defmodule PowerDNSex.ZonesManagerTest do
@tag :zones_manager_delete
test "return given correct params" do
use_cassette "zones_manager/delete/success" do
- assert ZonesManager.delete("success-delete.com") == :ok
+ assert ZonesManager.delete(@valid_zone_test.name) == :ok
end
end
@tag :zones_manager_delete
test "return error when zone don't exists" do
use_cassette "zones_manager/delete/not_found" do
- response = ZonesManager.delete("not_found.com")
- assert response.error == "Could not find domain 'not_found.com.'"
+ response = ZonesManager.delete(@unknown_name)
+ assert response.error == "Could not find domain '#{@unknown_name}'"
end
end
end
diff --git a/test/support/cassettes/records_manager/update/invalid_record.json b/test/support/cassettes/records_manager/update/invalid_record.json
new file mode 100644
index 0000000..df6d73a
--- /dev/null
+++ b/test/support/cassettes/records_manager/update/invalid_record.json
@@ -0,0 +1,31 @@
+[
+ {
+ "request": {
+ "body": "{\"rrsets\":[{\"type\":\"NS\",\"ttl\":86800,\"records\":[{\"disabled\":true,\"content\":\"127.0.0.1\"}],\"name\":\"updated-record.my-domain.art.\",\"changetype\":\"REPLACE\"}]}",
+ "headers": {
+ "X-API-Key": "Locaweb2016"
+ },
+ "method": "patch",
+ "options": [],
+ "request_body": "",
+ "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/my-domain.art."
+ },
+ "response": {
+ "body": "{\"error\": \"Record updated-record.my-domain.art./NS '127.0.0.1': Not in expected format (parsed as '127.0.0.1.')\"}",
+ "headers": {
+ "Access-Control-Allow-Origin": "*",
+ "Connection": "close",
+ "Content-Length": "113",
+ "Content-Security-Policy": "default-src 'self'; style-src 'self' 'unsafe-inline'",
+ "Content-Type": "application/json",
+ "Server": "PowerDNS/4.0.1",
+ "X-Content-Type-Options": "nosniff",
+ "X-Frame-Options": "deny",
+ "X-Permitted-Cross-Domain-Policies": "none",
+ "X-Xss-Protection": "1; mode=block"
+ },
+ "status_code": 422,
+ "type": "ok"
+ }
+ }
+] \ No newline at end of file
diff --git a/test/support/cassettes/records_manager/update/not_found.json b/test/support/cassettes/records_manager/update/not_found.json
new file mode 100644
index 0000000..38edad2
--- /dev/null
+++ b/test/support/cassettes/records_manager/update/not_found.json
@@ -0,0 +1,31 @@
+[
+ {
+ "request": {
+ "body": "{\"rrsets\":[{\"type\":\"A\",\"ttl\":86800,\"records\":[{\"disabled\":true,\"content\":\"127.0.0.1\"}],\"name\":\"updated-record.my-domain.art.\",\"changetype\":\"REPLACE\"}]}",
+ "headers": {
+ "X-API-Key": "Locaweb2016"
+ },
+ "method": "patch",
+ "options": [],
+ "request_body": "",
+ "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/not-canonical-domain.tst"
+ },
+ "response": {
+ "body": "{\"error\": \"Could not find domain 'not-canonical-domain.tst.'\"}",
+ "headers": {
+ "Access-Control-Allow-Origin": "*",
+ "Connection": "close",
+ "Content-Length": "62",
+ "Content-Security-Policy": "default-src 'self'; style-src 'self' 'unsafe-inline'",
+ "Content-Type": "application/json",
+ "Server": "PowerDNS/4.0.1",
+ "X-Content-Type-Options": "nosniff",
+ "X-Frame-Options": "deny",
+ "X-Permitted-Cross-Domain-Policies": "none",
+ "X-Xss-Protection": "1; mode=block"
+ },
+ "status_code": 422,
+ "type": "ok"
+ }
+ }
+] \ No newline at end of file
diff --git a/test/support/cassettes/zones_manager/delete/not_found.json b/test/support/cassettes/zones_manager/delete/not_found.json
index ab1540c..0637299 100644
--- a/test/support/cassettes/zones_manager/delete/not_found.json
+++ b/test/support/cassettes/zones_manager/delete/not_found.json
@@ -8,10 +8,10 @@
"method": "delete",
"options": [],
"request_body": "",
- "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/not_found.com"
+ "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/it-will-never-exist.on.the.art."
},
"response": {
- "body": "{\"error\": \"Could not find domain 'not_found.com.'\"}",
+ "body": "{\"error\": \"Could not find domain 'it-will-never-exist.on.the.art.'\"}",
"headers": {
"Access-Control-Allow-Origin": "*",
"Connection": "close",
diff --git a/test/support/cassettes/zones_manager/delete/success.json b/test/support/cassettes/zones_manager/delete/success.json
index 655ebe7..2f3fe90 100644
--- a/test/support/cassettes/zones_manager/delete/success.json
+++ b/test/support/cassettes/zones_manager/delete/success.json
@@ -8,7 +8,7 @@
"method": "delete",
"options": [],
"request_body": "",
- "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/success-delete.com"
+ "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/my-domain.art."
},
"response": {
"body": "",