summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-03-06 11:30:05 +0100
committerMartin Polden <mpolden@mpolden.no>2018-03-06 11:36:35 +0100
commit4e5fef4c41e23d94953a37f146e9baea3e3af3ea (patch)
tree7cafde17f745b84998746a6d6de4c9f6abc33a5d
parent7cc34bd91b9d8a685947e47d91a4827367113b05 (diff)
Simplify testing of responses with dynamic content
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java54
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-config-server.json165
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-docker-host.json75
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-tenant-node.json120
4 files changed, 374 insertions, 40 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
index bdea767eb0d..0e9e3464c02 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
@@ -13,6 +13,7 @@ import com.yahoo.vespa.config.SlimeUtils;
import com.yahoo.vespa.hosted.provision.testutils.ContainerConfig;
import org.junit.After;
import org.junit.Before;
+import org.junit.ComparisonFailure;
import org.junit.Test;
import java.io.File;
@@ -330,47 +331,17 @@ public class RestApiTest {
assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/" + hostname,
new byte[0], Request.Method.PUT),
"{\"message\":\"Moved foo.yahoo.com to ready\"}");
- Pattern responsePattern = Pattern.compile("\\{\"trustedNodes\":\\[.*" +
- "\\{\"hostname\":\"cfg1\",\"ipAddress\":\".+?\",\"trustedBy\":\"foo.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg2\",\"ipAddress\":\".+?\",\"trustedBy\":\"foo.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg3\",\"ipAddress\":\".+?\",\"trustedBy\":\"foo.yahoo.com\"}" +
- ".*],\"trustedNetworks\":\\[\\]}");
- assertResponseMatches(new Request("http://localhost:8080/nodes/v2/acl/" + hostname), responsePattern);
+ assertFile(new Request("http://localhost:8080/nodes/v2/acl/" + hostname), "acl-tenant-node.json");
}
@Test
public void acl_request_by_config_server() throws Exception {
- Pattern responsePattern = Pattern.compile("\\{\"trustedNodes\":\\[.*" +
- "\\{\"hostname\":\"cfg1\",\"ipAddress\":\".+?\",\"trustedBy\":\"cfg1\"}," +
- "\\{\"hostname\":\"cfg2\",\"ipAddress\":\".+?\",\"trustedBy\":\"cfg1\"}," +
- "\\{\"hostname\":\"cfg3\",\"ipAddress\":\".+?\",\"trustedBy\":\"cfg1\"}" +
- ".*],\"trustedNetworks\":\\[\\]}");
- assertResponseMatches(new Request("http://localhost:8080/nodes/v2/acl/cfg1"), responsePattern);
+ assertFile(new Request("http://localhost:8080/nodes/v2/acl/cfg1"), "acl-config-server.json");
}
@Test
public void acl_request_by_docker_host() throws Exception {
- Pattern responsePattern = Pattern.compile("\\{\"trustedNodes\":\\[" +
- "\\{\"hostname\":\"cfg1\",\"ipAddress\":\".+?\",\"trustedBy\":\"dockerhost1.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg2\",\"ipAddress\":\".+?\",\"trustedBy\":\"dockerhost1.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg3\",\"ipAddress\":\".+?\",\"trustedBy\":\"dockerhost1.yahoo.com\"}]," +
- "\"trustedNetworks\":\\[" +
- "\\{\"network\":\"172.17.0.0/16\",\"trustedBy\":\"dockerhost1.yahoo.com\"}]}");
- assertResponseMatches(new Request("http://localhost:8080/nodes/v2/acl/dockerhost1.yahoo.com"), responsePattern);
- }
-
- @Test
- public void acl_response_with_dual_stack_node() throws Exception {
- Pattern responsePattern = Pattern.compile("\\{\"trustedNodes\":\\[" +
- "\\{\"hostname\":\"cfg1\",\"ipAddress\":\".+?\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg2\",\"ipAddress\":\".+?\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"cfg3\",\"ipAddress\":\".+?\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"host1.yahoo.com\",\"ipAddress\":\"::1\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"host1.yahoo.com\",\"ipAddress\":\"127.0.0.1\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"host10.yahoo.com\",\"ipAddress\":\"::1\",\"trustedBy\":\"host1.yahoo.com\"}," +
- "\\{\"hostname\":\"host10.yahoo.com\",\"ipAddress\":\"127.0.0.1\",\"trustedBy\":\"host1.yahoo.com\"}" +
- "],\"trustedNetworks\":\\[\\]}");
- assertResponseMatches(new Request("http://localhost:8080/nodes/v2/acl/host1.yahoo.com"), responsePattern);
+ assertFile(new Request("http://localhost:8080/nodes/v2/acl/dockerhost1.yahoo.com"), "acl-docker-host.json");
}
@Test
@@ -609,18 +580,21 @@ public class RestApiTest {
response.contains(responseSnippet));
}
- private void assertResponseMatches(Request request, Pattern pattern) throws IOException {
- String response = container.handleRequest(request).getBodyAsString();
- assertTrue(String.format("Expected response to match pattern: %s\nResponse: %s", pattern.toString(), response),
- pattern.matcher(response).matches());
- }
-
private void assertFile(Request request, String responseFile) throws IOException {
String expectedResponse = IOUtils.readFile(new File(responsesPath + responseFile));
expectedResponse = include(expectedResponse);
expectedResponse = expectedResponse.replaceAll("\\s", "");
String responseString = container.handleRequest(request).getBodyAsString();
- assertEquals(responseFile, expectedResponse, responseString);
+ if (expectedResponse.contains("(ignore)")) {
+ String expectedResponsePattern = Pattern.quote(expectedResponse)
+ .replaceAll("\\(ignore\\)", "\\\\E.*\\\\Q");
+ if (!Pattern.matches(expectedResponsePattern, responseString)) {
+ throw new ComparisonFailure(responseFile + " (with ignored fields)", expectedResponsePattern,
+ responseString);
+ }
+ } else {
+ assertEquals(responseFile, expectedResponse, responseString);
+ }
}
private void assertRestart(int restartCount, Request request) throws IOException {
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-config-server.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-config-server.json
new file mode 100644
index 00000000000..af925e9f94e
--- /dev/null
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-config-server.json
@@ -0,0 +1,165 @@
+{
+ "trustedNodes": [
+ {
+ "hostname": "cfg1",
+ "ipAddress": "(ignore)",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "cfg2",
+ "ipAddress": "(ignore)",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "cfg3",
+ "ipAddress": "(ignore)",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost1.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost1.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost2.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost2.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost3.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost3.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost4.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost4.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost5.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "dockerhost5.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host1.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host1.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host10.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host10.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host2.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host2.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host3.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host3.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host4.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host4.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host5.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host5.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host55.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host55.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host6.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host6.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host7.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "host7.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "cfg1"
+ },
+ {
+ "hostname": "test-container-1",
+ "ipAddress": "::2",
+ "trustedBy": "cfg1"
+ }
+ ],
+ "trustedNetworks": []
+}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-docker-host.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-docker-host.json
new file mode 100644
index 00000000000..195edac7cce
--- /dev/null
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-docker-host.json
@@ -0,0 +1,75 @@
+{
+ "trustedNodes": [
+ {
+ "hostname": "cfg1",
+ "ipAddress": "(ignore)",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "cfg2",
+ "ipAddress": "(ignore)",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "cfg3",
+ "ipAddress": "(ignore)",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost1.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost1.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost2.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost2.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost3.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost3.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost4.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost4.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost5.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ },
+ {
+ "hostname": "dockerhost5.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "dockerhost1.yahoo.com"
+ }
+ ],
+ "trustedNetworks": [
+ {
+ "network": "172.17.0.0/16",
+ "trustedBy": "dockerhost1.yahoo.com"
+ }
+ ]
+}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-tenant-node.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-tenant-node.json
new file mode 100644
index 00000000000..eb7a6ba61bb
--- /dev/null
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/acl-tenant-node.json
@@ -0,0 +1,120 @@
+{
+ "trustedNodes": [
+ {
+ "hostname": "cfg1",
+ "ipAddress": "(ignore)",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "cfg2",
+ "ipAddress": "(ignore)",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "cfg3",
+ "ipAddress": "(ignore)",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "foo.yahoo.com",
+ "ipAddress": "(ignore)",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host1.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host1.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host10.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host10.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host2.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host2.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host3.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host3.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host4.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host4.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host5.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host5.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host55.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host55.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host6.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host6.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host7.yahoo.com",
+ "ipAddress": "::1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "host7.yahoo.com",
+ "ipAddress": "127.0.0.1",
+ "trustedBy": "foo.yahoo.com"
+ },
+ {
+ "hostname": "test-container-1",
+ "ipAddress": "::2",
+ "trustedBy": "foo.yahoo.com"
+ }
+ ],
+ "trustedNetworks": []
+}