aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-osgi-testrunner
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-11-18 14:08:58 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-11-18 14:08:58 +0100
commit40a864437bb2e6d23311120becd89b452d5c3319 (patch)
treea75bc70cf0a3f24e478ab8e49f5ffc713d3ab1a2 /vespa-osgi-testrunner
parent6c935eae4f019d479644d53396487f32a7de2858 (diff)
Copy credentials to where vespa-cli will find them
Diffstat (limited to 'vespa-osgi-testrunner')
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java21
-rw-r--r--vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java73
2 files changed, 58 insertions, 36 deletions
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java
index f65a4b60d35..703dfe6cd1b 100644
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java
@@ -76,7 +76,11 @@ public class VespaCliTestRunner implements TestRunner {
void runTests(Suite suite, byte[] config) {
Process process = null;
try {
- process = testRunProcessBuilder(suite, toEndpointsConfig(config)).start();
+ TestConfig testConfig = TestConfig.fromJson(config);
+ Path credentialsPath = artifactsPath.resolve(testConfig.application().toFullString());
+ copyCredentials(credentialsPath);
+
+ process = testRunProcessBuilder(suite, testConfig).start();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
in.lines().forEach(line -> {
if (line.length() > 1 << 13)
@@ -95,12 +99,20 @@ public class VespaCliTestRunner implements TestRunner {
}
}
- ProcessBuilder testRunProcessBuilder(Suite suite, String endpointsConfig) {
+ void copyCredentials(Path credentialsPath) throws IOException {
+ Files.createDirectories(credentialsPath);
+ Files.copy(artifactsPath.resolve("key"), credentialsPath.resolve("data-plane-private-key.pem"));
+ Files.copy(artifactsPath.resolve("cert"), credentialsPath.resolve("data-plane-public-cert.pem"));
+ }
+
+ ProcessBuilder testRunProcessBuilder(Suite suite, TestConfig config) throws IOException {
Path suitePath = getChildDirectory(artifactsPath, "tests")
.flatMap(testsPath -> getChildDirectory(testsPath, toSuiteDirectoryName(suite)))
.orElseThrow(() -> new IllegalStateException("No tests found, for suite '" + suite + "'"));
- ProcessBuilder builder = new ProcessBuilder("vespa", "test", "--endpoints", endpointsConfig);
+ ProcessBuilder builder = new ProcessBuilder("vespa", "test",
+ "--application", config.application().toFullString(),
+ "--endpoints", toEndpointsConfig(config));
builder.redirectErrorStream(true);
builder.directory(suitePath.toFile());
return builder;
@@ -133,8 +145,7 @@ public class VespaCliTestRunner implements TestRunner {
}
}
- static String toEndpointsConfig(byte[] testConfig) throws IOException {
- TestConfig config = TestConfig.fromJson(testConfig);
+ static String toEndpointsConfig(TestConfig config) throws IOException {
Cursor root = new Slime().setObject();
Cursor endpointsArray = root.setArray("endpoints");
config.deployments().get(config.zone()).forEach((cluster, url) -> {
diff --git a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java
index 68d44a386f8..59bb918134a 100644
--- a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java
+++ b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java
@@ -1,14 +1,18 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
+import ai.vespa.hosted.api.TestConfig;
+import com.yahoo.config.provision.ApplicationId;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -19,34 +23,28 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
class VespaCliTestRunnerTest {
- @Test
- void testEndpointsConfig() throws IOException {
- byte[] testConfig = ("{\n" +
- " \"application\": \"t:a:i\",\n" +
- " \"zone\": \"dev.aws-us-east-1c\",\n" +
- " \"system\": \"publiccd\",\n" +
- " \"isCI\": true,\n" +
- " \"zoneEndpoints\": {\n" +
- " \"dev.aws-us-east-1c\": {\n" +
- " \"default\": \"https://dev.endpoint:443/\"\n" +
- " },\n" +
- " \"prod.aws-us-east-1a\": {\n" +
- " \"default\": \"https://prod.endpoint:443/\"\n" +
- " }\n" +
- " },\n" +
- " \"clusters\": {\n" +
- " \"prod.aws-us-east-1c\": [\n" +
- " \"documents\"\n" +
- " ]\n" +
- " }\n" +
- "}\n").getBytes(StandardCharsets.UTF_8);
-
- assertEquals("{\"endpoints\":[{\"cluster\":\"default\",\"url\":\"https://dev.endpoint:443/\"}]}",
- VespaCliTestRunner.toEndpointsConfig(testConfig));
- }
+ static final TestConfig testConfig = TestConfig.fromJson(("{\n" +
+ " \"application\": \"t:a:i\",\n" +
+ " \"zone\": \"dev.aws-us-east-1c\",\n" +
+ " \"system\": \"publiccd\",\n" +
+ " \"isCI\": true,\n" +
+ " \"zoneEndpoints\": {\n" +
+ " \"dev.aws-us-east-1c\": {\n" +
+ " \"default\": \"https://dev.endpoint:443/\"\n" +
+ " },\n" +
+ " \"prod.aws-us-east-1a\": {\n" +
+ " \"default\": \"https://prod.endpoint:443/\"\n" +
+ " }\n" +
+ " },\n" +
+ " \"clusters\": {\n" +
+ " \"prod.aws-us-east-1c\": [\n" +
+ " \"documents\"\n" +
+ " ]\n" +
+ " }\n" +
+ "}\n").getBytes(StandardCharsets.UTF_8));
@Test
- void testSuitePathDiscovery() throws IOException {
+ void testSetup() throws IOException {
Path temp = Files.createTempDirectory("vespa-cli-test-runner-test-");
temp.toFile().deleteOnExit();
VespaCliTestRunner runner = new VespaCliTestRunner(temp);
@@ -54,14 +52,27 @@ class VespaCliTestRunnerTest {
Path tests = Files.createDirectory(temp.resolve("tests"));
assertTrue(runner.isSupported());
- IllegalStateException expected = assertThrows(IllegalStateException.class,
- () -> runner.testRunProcessBuilder(TestRunner.Suite.SYSTEM_TEST, ""));
- assertEquals("No tests found, for suite 'SYSTEM_TEST'", expected.getMessage());
+ IllegalStateException ise = assertThrows(IllegalStateException.class,
+ () -> runner.testRunProcessBuilder(TestRunner.Suite.SYSTEM_TEST, testConfig));
+ assertEquals("No tests found, for suite 'SYSTEM_TEST'", ise.getMessage());
Path systemTests = Files.createDirectory(tests.resolve("system-test"));
- ProcessBuilder builder = runner.testRunProcessBuilder(TestRunner.Suite.SYSTEM_TEST, "config");
+ ProcessBuilder builder = runner.testRunProcessBuilder(TestRunner.Suite.SYSTEM_TEST, testConfig);
assertEquals(systemTests.toFile(), builder.directory());
- assertEquals(List.of("vespa", "test", "--endpoints", "config"), builder.command());
+ assertEquals(List.of("vespa", "test",
+ "--application", "t.a.i",
+ "--endpoints", "{\"endpoints\":[{\"cluster\":\"default\",\"url\":\"https://dev.endpoint:443/\"}]}"),
+ builder.command());
+
+ Path credentialsPath = temp.resolve("creds");
+ assertThrows(NoSuchFileException.class,
+ () -> runner.copyCredentials(credentialsPath));
+
+ Files.write(temp.resolve("key"), new byte[]{ 0 });
+ Files.write(temp.resolve("cert"), new byte[]{ 1 });
+ runner.copyCredentials(credentialsPath);
+ assertArrayEquals(new byte[]{ 0 }, Files.readAllBytes(credentialsPath.resolve("data-plane-private-key.pem")));
+ assertArrayEquals(new byte[]{ 1 }, Files.readAllBytes(credentialsPath.resolve("data-plane-public-cert.pem")));
}
}