Skip to content

Commit

Permalink
[Integration Tests] Force utilization of -Dproject during tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 519739157
  • Loading branch information
bvolpato authored and cloud-teleport committed Mar 27, 2023
1 parent 879d072 commit e7dbfec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public DefaultDatastoreResourceManager(Builder builder) {
this.namespace = builder.namespace;

this.datastore =
DatastoreOptions.newBuilder().setCredentials(builder.credentials).build().getService();
DatastoreOptions.newBuilder()
.setProjectId(builder.project)
.setCredentials(builder.credentials)
.build()
.getService();
this.keys = new HashSet<>();
}

Expand Down Expand Up @@ -111,17 +115,20 @@ public void cleanupAll() {
keys.clear();
}

public static Builder builder(String namespace) {
public static Builder builder(String project, String namespace) {
checkArgument(!Strings.isNullOrEmpty(project), "project can not be empty");
checkArgument(!Strings.isNullOrEmpty(namespace), "namespace can not be empty");
return new Builder(namespace);
return new Builder(project, namespace);
}

public static final class Builder {

private final String project;
private final String namespace;
private Credentials credentials;

private Builder(String namespace) {
private Builder(String project, String namespace) {
this.project = project;
this.namespace = namespace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class DefaultDatastoreResourceManagerIT {
@Test
public void testInsert() throws IOException {
DefaultDatastoreResourceManager resourceManager =
DefaultDatastoreResourceManager.builder(DatastoreUtils.createTestId("testInsert"))
DefaultDatastoreResourceManager.builder(
TestProperties.project(), DatastoreUtils.createTestId("testInsert"))
.credentials(TestProperties.credentials())
.build();
List<Entity> entities =
Expand All @@ -49,7 +50,8 @@ public void testInsert() throws IOException {
@Test
public void testInsertQuery() throws IOException {
DefaultDatastoreResourceManager resourceManager =
DefaultDatastoreResourceManager.builder(DatastoreUtils.createTestId("testInsertQuery"))
DefaultDatastoreResourceManager.builder(
TestProperties.project(), DatastoreUtils.createTestId("testInsertQuery"))
.credentials(TestProperties.buildCredentialsFromEnv())
.build();

Expand All @@ -71,7 +73,8 @@ public void testInsertQuery() throws IOException {
@Test
public void testInsertCleanUp() throws IOException {
DefaultDatastoreResourceManager resourceManager =
DefaultDatastoreResourceManager.builder(DatastoreUtils.createTestId("testInsertCleanUp"))
DefaultDatastoreResourceManager.builder(
TestProperties.project(), DatastoreUtils.createTestId("testInsertCleanUp"))
.credentials(TestProperties.buildCredentialsFromEnv())
.build();
resourceManager.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void setup() {
.setCredentials(credentials)
.build();
datastoreResourceManager =
DefaultDatastoreResourceManager.builder(testId).credentials(credentials).build();
DefaultDatastoreResourceManager.builder(PROJECT, testId).credentials(credentials).build();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public final class TextToDatastoreIT extends TemplateTestBase {

@Before
public void setup() {
testId = PipelineUtils.createJobName("");
testId = PipelineUtils.createJobName("test");

datastoreResourceManager =
DefaultDatastoreResourceManager.builder(testId).credentials(credentials).build();
DefaultDatastoreResourceManager.builder(PROJECT, testId).credentials(credentials).build();
}

@After
Expand Down

0 comments on commit e7dbfec

Please sign in to comment.