Skip to content

Commit 3833d56

Browse files
author
Les Vogel
committed
Update QuickStartIT.java
Fixes: #2715 Reviewing QuickstartIT, it: * creates a bucket * Writes a list of assets to the bucket * wants to see that bucket in the list of assets * deletes the bucket. It should instead: * Write to a well known bucket w/ gs:/well-known-bucket/UUID/my-assets.txt * See if well-known-bucket is in my-assets.txt This way there isn't a hysteresis problem on creating and knowing about buckets.
1 parent c95a52f commit 3833d56

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

asset/cloud-client/src/test/java/com/example/asset/QuickStartIT.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020

2121
import com.google.cloud.storage.BlobInfo;
22-
import com.google.cloud.storage.Bucket;
23-
import com.google.cloud.storage.BucketInfo;
2422
import com.google.cloud.storage.Storage;
2523
import com.google.cloud.storage.Storage.BlobListOption;
2624
import com.google.cloud.storage.StorageOptions;
@@ -37,31 +35,27 @@
3735
@RunWith(JUnit4.class)
3836
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3937
public class QuickStartIT {
40-
private static final String bucketName = UUID.randomUUID().toString();
38+
private static final String bucketName = "java-docs-samples-testing";
39+
private static final String path = UUID.randomUUID().toString();
4140
private ByteArrayOutputStream bout;
4241
private PrintStream out;
4342

44-
private static final void deleteBucket(String bucketName) {
43+
private static final void deleteObjects() {
4544
Storage storage = StorageOptions.getDefaultInstance().getService();
46-
for (BlobInfo info : storage.list(bucketName, BlobListOption.versions(true)).getValues()) {
45+
for (BlobInfo info :
46+
storage
47+
.list(
48+
bucketName,
49+
BlobListOption.versions(true),
50+
BlobListOption.currentDirectory(),
51+
BlobListOption.prefix(path + "/"))
52+
.getValues()) {
4753
storage.delete(info.getBlobId());
4854
}
49-
storage.delete(bucketName);
50-
}
51-
52-
private static final void createBucket(String bucketName) {
53-
Storage storage = StorageOptions.getDefaultInstance().getService();
54-
if (storage.get(bucketName) != null) {
55-
// Bucket exists.
56-
return;
57-
}
58-
Bucket bucket = storage.create(BucketInfo.of(bucketName));
59-
assertThat(bucket).isNotNull();
6055
}
6156

6257
@Before
6358
public void setUp() {
64-
createBucket(bucketName);
6559
bout = new ByteArrayOutputStream();
6660
out = new PrintStream(bout);
6761
System.setOut(out);
@@ -71,12 +65,12 @@ public void setUp() {
7165
public void tearDown() {
7266
String consoleOutput = bout.toString();
7367
System.setOut(null);
74-
deleteBucket(bucketName);
68+
deleteObjects();
7569
}
7670

7771
@Test
7872
public void testExportAssetExample() throws Exception {
79-
String assetDumpPath = String.format("gs://%s/my-assets-dump.txt", bucketName);
73+
String assetDumpPath = String.format("gs://%s/%s/my-assets-dump.txt", bucketName, path);
8074
ExportAssetsExample.main(assetDumpPath);
8175
String got = bout.toString();
8276
assertThat(got).contains(String.format("uri: \"%s\"", assetDumpPath));

0 commit comments

Comments
 (0)