Skip to content

Commit ae3c13c

Browse files
committed
feat(secretmanager):fixed tests
1 parent 5590223 commit ae3c13c

File tree

2 files changed

+111
-70
lines changed

2 files changed

+111
-70
lines changed

secretmanager/src/test/java/secretmanager/SnippetsIT.java

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -170,65 +170,69 @@ private static String randomSecretId() {
170170

171171
private static void createTags() throws IOException{
172172
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
173-
Random random = new Random();
174-
ProjectName parent = ProjectName.of(PROJECT_ID);
175-
CreateTagKeyRequest request =
176-
CreateTagKeyRequest.newBuilder()
177-
.setTagKey(
178-
TagKey
179-
.newBuilder()
180-
.setParent(parent.toString())
181-
.setShortName("java-" + random.nextLong())
182-
.build())
183-
.build();
184-
OperationFuture<TagKey, CreateTagKeyMetadata> future =
185-
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
186-
TagKey response = future.get();
187-
TAG_KEY = response;
173+
Random random = new Random();
174+
ProjectName parent = ProjectName.of(PROJECT_ID);
175+
CreateTagKeyRequest request =
176+
CreateTagKeyRequest.newBuilder()
177+
.setTagKey(
178+
TagKey
179+
.newBuilder()
180+
.setParent(parent.toString())
181+
.setShortName("java-" + random.nextLong())
182+
.build())
183+
.build();
184+
OperationFuture<TagKey, CreateTagKeyMetadata> future =
185+
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
186+
TagKey response = future.get();
187+
TAG_KEY = response;
188188
}catch(Exception e){
189+
System.out.printf("Unable to create Tag Key %s\n", e.toString());
189190
}
190-
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
191-
Random random = new Random();
192-
CreateTagValueRequest request =
193-
CreateTagValueRequest.newBuilder()
194-
.setTagValue(TagValue
195-
.newBuilder()
196-
.setParent(TAG_KEY.getName())
197-
.setShortName("java-" + random.nextLong())
198-
.build())
199-
.build();
200-
OperationFuture<TagValue, CreateTagValueMetadata> future =
201-
tagValuesClient.createTagValueOperationCallable().futureCall(request);
202-
TagValue response = future.get();
203-
TAG_VALUE = response;
204-
}catch(Exception e){
205-
}
206191

192+
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
193+
Random random = new Random();
194+
CreateTagValueRequest request =
195+
CreateTagValueRequest.newBuilder()
196+
.setTagValue(
197+
TagValue
198+
.newBuilder()
199+
.setParent(TAG_KEY.getName())
200+
.setShortName("java-" + random.nextLong())
201+
.build())
202+
.build();
203+
OperationFuture<TagValue, CreateTagValueMetadata> future =
204+
tagValuesClient.createTagValueOperationCallable().futureCall(request);
205+
TagValue response = future.get();
206+
TAG_VALUE = response;
207+
}catch(Exception e){
208+
System.out.printf("Unable to create Tag Value %s\n", e.toString());
209+
}
207210
}
208211

209212
private static void deleteTags() throws IOException{
210213
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
211-
DeleteTagValueRequest request =
212-
DeleteTagValueRequest.newBuilder()
213-
.setName(TAG_VALUE.getName())
214-
.build();
215-
OperationFuture<TagValue, DeleteTagValueMetadata> future =
216-
tagValuesClient.deleteTagValueOperationCallable().futureCall(request);
217-
TagValue response = future.get();
218-
}catch(Exception e){
219-
}
220-
221-
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
222-
DeleteTagKeyRequest request =
223-
DeleteTagKeyRequest.newBuilder()
224-
.setName(TAG_KEY.getName())
225-
.build();
226-
OperationFuture<TagKey, DeleteTagKeyMetadata> future =
227-
tagKeysClient.deleteTagKeyOperationCallable().futureCall(request);
228-
TagKey response = future.get();
229-
}catch(Exception e){
230-
}
214+
DeleteTagValueRequest request =
215+
DeleteTagValueRequest.newBuilder()
216+
.setName(TAG_VALUE.getName())
217+
.build();
218+
OperationFuture<TagValue, DeleteTagValueMetadata> future =
219+
tagValuesClient.deleteTagValueOperationCallable().futureCall(request);
220+
TagValue response = future.get();
221+
}catch(Exception e){
222+
System.out.printf("Unable to delete Tag key %s\n", e.toString());
223+
}
231224

225+
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
226+
DeleteTagKeyRequest request =
227+
DeleteTagKeyRequest.newBuilder()
228+
.setName(TAG_KEY.getName())
229+
.build();
230+
OperationFuture<TagKey, DeleteTagKeyMetadata> future =
231+
tagKeysClient.deleteTagKeyOperationCallable().futureCall(request);
232+
TagKey response = future.get();
233+
}catch(Exception e){
234+
System.out.printf("Unable to delete Tag Value %s\n", e.toString());
235+
}
232236
}
233237

234238
private static Secret createSecret(boolean addAnnotation) throws IOException {

secretmanager/src/test/java/secretmanager/regionalsamples/SnippetsIT.java

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import com.google.cloud.resourcemanager.v3.CreateTagKeyRequest;
2828
import com.google.cloud.resourcemanager.v3.CreateTagValueMetadata;
2929
import com.google.cloud.resourcemanager.v3.CreateTagValueRequest;
30+
import com.google.cloud.resourcemanager.v3.DeleteTagKeyMetadata;
31+
import com.google.cloud.resourcemanager.v3.DeleteTagKeyRequest;
32+
import com.google.cloud.resourcemanager.v3.DeleteTagValueMetadata;
33+
import com.google.cloud.resourcemanager.v3.DeleteTagValueRequest;
3034
import com.google.api.gax.longrunning.OperationFuture;
3135
import com.google.cloud.resourcemanager.v3.TagKey;
3236
import com.google.cloud.resourcemanager.v3.TagKeysClient;
@@ -186,33 +190,66 @@ private static void createTags() throws IOException{
186190
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
187191
ProjectName parent = ProjectName.of(PROJECT_ID);
188192
Random random = new Random();
189-
CreateTagKeyRequest request =
190-
CreateTagKeyRequest.newBuilder()
191-
.setTagKey(TagKey.newBuilder().setParent(parent.toString())
192-
.setShortName("java-" + random.nextLong()).build())
193-
.build();
194-
OperationFuture<TagKey, CreateTagKeyMetadata> future =
195-
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
196-
TagKey response = future.get();
197-
TAG_KEY = response;
193+
CreateTagKeyRequest request =
194+
CreateTagKeyRequest.newBuilder()
195+
.setTagKey(
196+
TagKey.newBuilder()
197+
.setParent(parent.toString())
198+
.setShortName("java-" + random.nextLong())
199+
.build())
200+
.build();
201+
OperationFuture<TagKey, CreateTagKeyMetadata> future =
202+
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
203+
TagKey response = future.get();
204+
TAG_KEY = response;
198205
}catch(Exception e){
206+
System.out.printf("Unable to create Tag Key %s\n", e.toString());
199207
}
208+
200209
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
201210
Random random = new Random();
202-
CreateTagValueRequest request =
203-
CreateTagValueRequest.newBuilder()
204-
.setTagValue(TagValue.newBuilder().setParent(TAG_KEY.getName()).setShortName("java-" + random.nextLong()).build())
205-
.build();
206-
OperationFuture<TagValue, CreateTagValueMetadata> future =
207-
tagValuesClient.createTagValueOperationCallable().futureCall(request);
208-
TagValue response = future.get();
209-
TAG_VALUE = response;
210-
}catch(Exception e){
211-
}
211+
CreateTagValueRequest request =
212+
CreateTagValueRequest.newBuilder()
213+
.setTagValue(
214+
TagValue.newBuilder()
215+
.setParent(TAG_KEY.getName())
216+
.setShortName("java-" + random.nextLong())
217+
.build())
218+
.build();
219+
OperationFuture<TagValue, CreateTagValueMetadata> future =
220+
tagValuesClient.createTagValueOperationCallable().futureCall(request);
221+
TagValue response = future.get();
222+
TAG_VALUE = response;
223+
}catch(Exception e){
224+
System.out.printf("Unable to create Tag Value %s\n", e.toString());
225+
}
212226

213227
}
214228

215229
private static void deleteTags() throws IOException{
230+
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
231+
DeleteTagValueRequest request =
232+
DeleteTagValueRequest.newBuilder()
233+
.setName(TAG_VALUE.getName())
234+
.build();
235+
OperationFuture<TagValue, DeleteTagValueMetadata> future =
236+
tagValuesClient.deleteTagValueOperationCallable().futureCall(request);
237+
TagValue response = future.get();
238+
}catch(Exception e){
239+
System.out.printf("Unable to delete Tag key %s\n", e.toString());
240+
}
241+
242+
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
243+
DeleteTagKeyRequest request =
244+
DeleteTagKeyRequest.newBuilder()
245+
.setName(TAG_KEY.getName())
246+
.build();
247+
OperationFuture<TagKey, DeleteTagKeyMetadata> future =
248+
tagKeysClient.deleteTagKeyOperationCallable().futureCall(request);
249+
TagKey response = future.get();
250+
}catch(Exception e){
251+
System.out.printf("Unable to delete Tag Value %s\n", e.toString());
252+
}
216253
}
217254

218255
private static Secret createRegionalSecret() throws IOException {

0 commit comments

Comments
 (0)