Skip to content

Commit 55482c9

Browse files
authored
---
yaml --- r: 15319 b: refs/heads/autosynth-bigtable c: 6300b45 h: refs/heads/master i: 15317: 0e09d93 15315: 276b74d 15311: 9f5a78c
1 parent 1c339b5 commit 55482c9

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

  • branches/autosynth-bigtable/google-cloud-clients/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/it

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ refs/heads/autosynth-asset: cd8251de8c40e239ad24dcf9ed93ea2708a3eed5
126126
refs/heads/autosynth-automl: cced2f56bbef0499609073edbca6253e1df5e535
127127
refs/heads/autosynth-bigquerydatatransfer: a6667617707608b1dbfb02d59c22b5152f208da7
128128
refs/heads/autosynth-bigquerystorage: 14ab055598b943ae3f33f484e9fb1653355d08e7
129-
refs/heads/autosynth-bigtable: 4aef34d3fcaaa3d8f9ac1d0bea04208d175d839f
129+
refs/heads/autosynth-bigtable: 6300b452d3c54c9a68f36e142ee3efeca66842c9
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 781fdb430a60f9a6491f116e31e4e10118157bdb
132132
refs/heads/autosynth-datastore: af1fb76aa3eee02fe6f31f8fa1c72a4f048d149b

branches/autosynth-bigtable/google-cloud-clients/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/it/ITComputeTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
package com.google.cloud.compute.v1.it;
1717

1818
import static com.google.common.truth.Truth.assertThat;
19+
import static junit.framework.TestCase.fail;
1920

2021
import com.google.api.gax.core.FixedCredentialsProvider;
2122
import com.google.api.gax.paging.Page;
23+
import com.google.api.gax.rpc.InvalidArgumentException;
2224
import com.google.auth.Credentials;
2325
import com.google.auth.oauth2.GoogleCredentials;
2426
import com.google.cloud.ServiceOptions;
@@ -27,10 +29,14 @@
2729
import com.google.cloud.compute.v1.DiskTypeClient.AggregatedListDiskTypesPagedResponse;
2830
import com.google.cloud.compute.v1.DiskTypeSettings;
2931
import com.google.cloud.compute.v1.DiskTypesScopedList;
32+
import com.google.cloud.compute.v1.Instance;
33+
import com.google.cloud.compute.v1.InstanceClient;
34+
import com.google.cloud.compute.v1.InstanceSettings;
3035
import com.google.cloud.compute.v1.ListDiskTypesHttpRequest;
3136
import com.google.cloud.compute.v1.ProjectName;
3237
import com.google.cloud.compute.v1.ProjectRegionDiskTypeName;
3338
import com.google.cloud.compute.v1.ProjectZoneDiskTypeName;
39+
import com.google.cloud.compute.v1.ProjectZoneMachineTypeName;
3440
import com.google.cloud.compute.v1.ProjectZoneName;
3541
import com.google.common.collect.Lists;
3642
import java.io.IOException;
@@ -52,6 +58,9 @@ public class ITComputeTest {
5258
private static DiskTypeClient diskTypeClient;
5359
private static DiskTypeSettings diskTypeSettings;
5460

61+
private static InstanceClient instanceClient;
62+
private static InstanceSettings instanceSettings;
63+
5564
@Rule public Timeout globalTimeout = Timeout.seconds(300);
5665

5766
@BeforeClass
@@ -65,11 +74,18 @@ public static void beforeClass() throws IOException {
6574
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
6675
.build();
6776
diskTypeClient = DiskTypeClient.create(diskTypeSettings);
77+
78+
instanceSettings =
79+
InstanceSettings.newBuilder()
80+
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
81+
.build();
82+
instanceClient = InstanceClient.create(instanceSettings);
6883
}
6984

7085
@AfterClass
7186
public static void tearDown() throws Exception {
7287
diskTypeClient.close();
88+
instanceClient.close();
7389
}
7490

7591
@Test
@@ -85,6 +101,26 @@ public void testGetDiskType() {
85101
assertThat(diskType.getDefaultDiskSizeGb()).isNotNull();
86102
}
87103

104+
@Test
105+
public void testInsertInstance() {
106+
String machineType =
107+
ProjectZoneMachineTypeName.of("n1-standard-1", DEFAULT_PROJECT, ZONE).toString();
108+
Instance instance =
109+
Instance.newBuilder().setName("mytestinstancetemplate").setMachineType(machineType).build();
110+
try {
111+
instanceClient.insertInstance(ProjectZoneName.of(DEFAULT_PROJECT, ZONE), instance);
112+
} catch (InvalidArgumentException e) {
113+
// Expect a Bad Request HTTP 400 error, but it should NOT be because of a resource name
114+
// problem.
115+
assertThat(e.getMessage()).contains("Bad Request");
116+
assertThat(e.getCause().getMessage())
117+
.contains("Invalid value for field 'resource.networkInterfaces'");
118+
return;
119+
}
120+
121+
fail("Expected HTTP Bad Request to be returned, but it was not returned.");
122+
}
123+
88124
@Test
89125
public void testListDiskTypes() {
90126
Page<DiskType> diskPage =

0 commit comments

Comments
 (0)