Skip to content
Permalink
Browse files
fix: updates project / instance for samples tests (#613)
* fix: updates project / instance for samples tests

Updates the project and instance for the samples tests, so that they use
the same configuration as the integration tests.

* fix: excludes modified kokoro / pom.xml files

Excludes modified kokoro / pom.xml files from the synth.

* fix: fixes the account used to run samples tests

* fix: creates quickstart db for test

Creates the quickstart database for the integration test.
  • Loading branch information
thiagotnunes committed Nov 11, 2020
1 parent 35cc56c commit 2589e7d6f400a7b050c21f46a4ab1662baa1cdb7
@@ -14,22 +14,22 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
value: "java-it-service-account"
}

env_vars: {
@@ -14,22 +14,22 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
value: "java-it-service-account"
}

env_vars: {
@@ -14,22 +14,22 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
value: "java-it-service-account"
}

env_vars: {
@@ -14,21 +14,21 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
value: "java-it-service-account"
}

@@ -14,21 +14,21 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
value: "java-it-service-account"
}

@@ -14,20 +14,20 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-docs-samples-service-account"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
}
value: "java-it-service-account"
}
@@ -142,9 +142,9 @@
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<spanner.test.instance>default-instance</spanner.test.instance>
<spanner.test.instance>spanner-testing</spanner.test.instance>
<spanner.sample.database>mysample</spanner.sample.database>
<spanner.quickstart.database>quickstart-db</spanner.quickstart.database>
<spanner.quickstart.database>quick-db</spanner.quickstart.database>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -141,9 +141,9 @@
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<spanner.test.instance>default-instance</spanner.test.instance>
<spanner.test.instance>spanner-testing</spanner.test.instance>
<spanner.sample.database>mysample</spanner.sample.database>
<spanner.quickstart.database>quickstart-db</spanner.quickstart.database>
<spanner.quickstart.database>quick-db</spanner.quickstart.database>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -146,9 +146,9 @@
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<spanner.test.instance>default-instance</spanner.test.instance>
<spanner.test.instance>spanner-testing</spanner.test.instance>
<spanner.sample.database>mysample</spanner.sample.database>
<spanner.quickstart.database>quickstart-db</spanner.quickstart.database>
<spanner.quickstart.database>quick-db</spanner.quickstart.database>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -18,10 +18,19 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseNotFoundException;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -32,13 +41,27 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class QuickstartSampleIT {
private String instanceId = System.getProperty("spanner.test.instance");
// This database needs to exist for test to pass.
private String dbId = System.getProperty("spanner.quickstart.database");
private static String instanceId = System.getProperty("spanner.test.instance");
private static String dbId = formatForTest(System.getProperty("spanner.quickstart.database"));
private static DatabaseAdminClient dbClient;

private ByteArrayOutputStream bout;
private PrintStream stdOut = System.out;
private PrintStream out;

@BeforeClass
public static void createDatabase() {
final SpannerOptions options = SpannerOptions.newBuilder().build();
final Spanner spanner = options.getService();
dbClient = spanner.getDatabaseAdminClient();
dbClient.createDatabase(instanceId, dbId, Collections.emptyList());
}

@AfterClass
public static void dropDatabase() {
dbClient.dropDatabase(instanceId, dbId);
}

@Before
public void setUp() {
bout = new ByteArrayOutputStream();
@@ -59,4 +82,8 @@ public void testQuickstart() throws Exception {
String got = bout.toString();
assertThat(got).contains("1");
}

private static String formatForTest(String name) {
return name + "-" + UUID.randomUUID().toString().substring(0, 20);
}
}
@@ -78,5 +78,14 @@
java.common_templates(excludes=[
'.kokoro/continuous/common.cfg',
'.kokoro/nightly/common.cfg',
'.kokoro/nightly/java8-samples.cfg',
'.kokoro/nightly/java11-samples.cfg',
'.kokoro/nightly/samples.cfg',
'.kokoro/presubmit/common.cfg',
'.kokoro/presubmit/java8-samples.cfg',
'.kokoro/presubmit/java11-samples.cfg',
'.kokoro/presubmit/samples.cfg',
'samples/install-without-bom/pom.xml',
'samples/snapshot/pom.xml',
'samples/snippets/pom.xml',
])

0 comments on commit 2589e7d

Please sign in to comment.