Skip to content

Commit

Permalink
fix: updates project / instance for samples tests (#613)
Browse files Browse the repository at this point in the history
* 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 2589e7d
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .kokoro/nightly/java11-samples.cfg
Expand Up @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions .kokoro/nightly/java8-samples.cfg
Expand Up @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions .kokoro/nightly/samples.cfg
Expand Up @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions .kokoro/presubmit/java11-samples.cfg
Expand Up @@ -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"
}

8 changes: 4 additions & 4 deletions .kokoro/presubmit/java8-samples.cfg
Expand Up @@ -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"
}

10 changes: 5 additions & 5 deletions .kokoro/presubmit/samples.cfg
Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions samples/install-without-bom/pom.xml
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions samples/snapshot/pom.xml
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
}
9 changes: 9 additions & 0 deletions synth.py
Expand Up @@ -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.