diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000000..56885a2df3 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,25 @@ +## Testing code that uses Google Cloud Storage + +`RemoteStorageHelper` contains convenience methods to make setting up and cleaning up the test buckets easier. To use this class: + +1. Create a test Google Cloud project. + +2. Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication]. + +3. Create a `RemoteStorageHelper` object using your project ID and JSON key. + Here is an example that uses the `RemoteStorageHelper` to create a bucket. + ```java + RemoteStorageHelper helper = + RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json")); + Storage storage = helper.getOptions().getService(); + String bucket = RemoteStorageHelper.generateBucketName(); + storage.create(BucketInfo.of(bucket)); + ``` + +4. Run your tests. + +5. Clean up the test project by using `forceDelete` to clear any buckets used. + Here is an example that clears the bucket created in Step 3 with a timeout of 5 seconds. + ```java + RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS); + ``` diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/package-info.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/package-info.java index 096e189de1..ae3f262846 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/package-info.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/package-info.java @@ -34,8 +34,7 @@ * RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS); * } * - * @see - * Google Cloud Java tools for testing + * @see Google Cloud + * Storage testing */ package com.google.cloud.storage.testing;