Skip to content

Commit

Permalink
Prevent Name collisions on tests (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnegrey authored Jun 12, 2019
1 parent a34b099 commit 3c59709
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -35,7 +36,6 @@ public class DatasetApiIT {
private static final String PROJECT_ID = "java-docs-samples-testing";
private static final String BUCKET = PROJECT_ID + "-vcm";
private static final String COMPUTE_REGION = "us-central1";
private static final String DATASET_NAME = "test_vision_dataset";
private ByteArrayOutputStream bout;
private PrintStream out;
private String datasetId;
Expand All @@ -54,8 +54,13 @@ public void tearDown() {

@Test
public void testCreateImportDeleteDataset() {
// Create a random dataset name with a length of 32 characters (max allowed by AutoML)
// To prevent name collisions when running tests in multiple java versions at once.
// AutoML doesn't allow "-", but accepts "_"
String datasetName = String.format("test_%s",
UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
// Act
DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, DATASET_NAME, false);
DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false);

// Assert
String got = bout.toString();
Expand Down

0 comments on commit 3c59709

Please sign in to comment.