Skip to content

Commit c43fb1d

Browse files
authored
test: Add test for CreateCloudStorageSubscriptionExample (#2516)
1 parent db956bd commit c43fb1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

samples/snippets/src/test/java/pubsub/AdminIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.cloud.bigquery.TableInfo;
3434
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
3535
import com.google.cloud.pubsub.v1.TopicAdminClient;
36+
import com.google.protobuf.Duration;
3637
import com.google.pubsub.v1.SubscriptionName;
3738
import com.google.pubsub.v1.TopicName;
3839
import java.io.ByteArrayOutputStream;
@@ -73,6 +74,12 @@ public class AdminIT {
7374
"java_samples_data_set" + _suffix.replace("-", "_");
7475
private static final String bigquerySubscriptionId = "iam-bigquery-subscription-" + _suffix;
7576
private static final String bigqueryTableId = "java_samples_table_" + _suffix;
77+
private static final String cloudStorageSubscriptionId =
78+
"iam-cloud-storage-subscription-" + _suffix;
79+
private static final String cloudStorageFilenamePrefix = "log_events_";
80+
private static final String cloudStorageFilenameSuffix = ".txt";
81+
private static final Duration cloudStorageMaxDuration =
82+
Duration.newBuilder().setSeconds(300).build();
7683
private static final String gcpServiceAccount =
7784
7885
// AWS Kinesis ingestion settings.
@@ -322,13 +329,30 @@ public void testAdmin() throws Exception {
322329
assertThat(bout.toString()).contains("Created a BigQuery subscription:");
323330
assertThat(bout.toString()).contains(bigqueryTablePath);
324331

332+
bout.reset();
333+
// Test create a Cloud Storage subscription.
334+
CreateCloudStorageSubscriptionExample.createCloudStorageSubscription(
335+
projectId,
336+
topicId,
337+
cloudStorageSubscriptionId,
338+
cloudStorageBucket,
339+
cloudStorageFilenamePrefix,
340+
cloudStorageFilenameSuffix,
341+
cloudStorageMaxDuration);
342+
assertThat(bout.toString()).contains("Created a CloudStorage subscription:");
343+
assertThat(bout.toString()).contains(cloudStorageBucket);
344+
assertThat(bout.toString()).contains(cloudStorageFilenamePrefix);
345+
assertThat(bout.toString()).contains(cloudStorageFilenameSuffix);
346+
assertThat(bout.toString()).contains(Long.toString(cloudStorageMaxDuration.getSeconds()));
347+
325348
bout.reset();
326349
// Test delete subscription.
327350
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId);
328351
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pushSubscriptionId);
329352
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, orderedSubscriptionId);
330353
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, exactlyOnceSubscriptionId);
331354
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, bigquerySubscriptionId);
355+
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, cloudStorageSubscriptionId);
332356
assertThat(bout.toString()).contains("Deleted subscription.");
333357

334358
bout.reset();

0 commit comments

Comments
 (0)