summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTiago Freire <code.tiago.frire@locaweb.com.br>2016-08-18 19:09:45 -0300
committerTiago Freire <code.tiago.frire@locaweb.com.br>2016-08-18 19:09:45 -0300
commita60bc8d12190237649bc577966b8f4b8b94d82a9 (patch)
treeb27dd45d04b3338ac0d660eb97fe47b9b0cad060 /test
parentMerge pull request #2 from akaKuruma/WIP (diff)
Add tests to uptade Record
Diffstat (limited to 'test')
-rw-r--r--test/lib/powerdnsex/managers/records_manager_test.exs32
-rw-r--r--test/support/cassettes/records_manager/update/invalid_record.json31
-rw-r--r--test/support/cassettes/records_manager/update/not_found.json31
3 files changed, 94 insertions, 0 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/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