Skip to content
This repository was archived by the owner on Jul 15, 2024. It is now read-only.

Commit 17f3b46

Browse files
tests: add test cases for int64 field, capital letter field, map pagination (#510)
* tests: more tests for compute * tests: imports * tests: fix * tests: formatting * tests: better assertions * tests: change string to long for int64
1 parent 5ed2d54 commit 17f3b46

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

‎google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITPaginationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
*/
1616
package com.google.cloud.compute.v1.integration;
1717

18+
import com.google.cloud.compute.v1.AcceleratorType;
19+
import com.google.cloud.compute.v1.AcceleratorTypesClient;
20+
import com.google.cloud.compute.v1.AcceleratorTypesScopedList;
21+
import com.google.cloud.compute.v1.AggregatedListAcceleratorTypesRequest;
1822
import com.google.cloud.compute.v1.ListZonesRequest;
1923
import com.google.cloud.compute.v1.Zone;
2024
import com.google.cloud.compute.v1.ZonesClient;
2125
import com.google.cloud.compute.v1.ZonesSettings;
2226
import com.google.common.collect.Lists;
2327
import java.io.IOException;
28+
import java.util.Map;
2429
import org.junit.AfterClass;
2530
import org.junit.Assert;
2631
import org.junit.BeforeClass;
@@ -116,4 +121,28 @@ public void testPaginationIterating() {
116121
}
117122
Assert.assertTrue(presented);
118123
}
124+
125+
@Test
126+
public void testPaginationAggregatedIterating() throws IOException {
127+
AcceleratorTypesClient acceleratorTypesClient = AcceleratorTypesClient.create();
128+
AggregatedListAcceleratorTypesRequest aggregatedListAcceleratorTypesRequest =
129+
AggregatedListAcceleratorTypesRequest.newBuilder()
130+
.setProject(DEFAULT_PROJECT)
131+
.setMaxResults(2)
132+
.build();
133+
AcceleratorTypesClient.AggregatedListPagedResponse response =
134+
acceleratorTypesClient.aggregatedList(aggregatedListAcceleratorTypesRequest);
135+
boolean presented = false;
136+
for (Map.Entry<String, AcceleratorTypesScopedList> entry : response.iterateAll()) {
137+
if (entry.getKey().equals("zones/" + DEFAULT_ZONE)) {
138+
for (AcceleratorType type : entry.getValue().getAcceleratorTypesList()) {
139+
if (type.getName().equals("nvidia-tesla-t4")) {
140+
presented = true;
141+
break;
142+
}
143+
}
144+
}
145+
}
146+
Assert.assertTrue(presented);
147+
}
119148
}

‎google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919

2020
import com.google.api.gax.rpc.InvalidArgumentException;
2121
import com.google.api.gax.rpc.NotFoundException;
22+
import com.google.cloud.compute.v1.Allowed;
2223
import com.google.cloud.compute.v1.AttachedDisk;
2324
import com.google.cloud.compute.v1.AttachedDiskInitializeParams;
25+
import com.google.cloud.compute.v1.Firewall;
26+
import com.google.cloud.compute.v1.FirewallsClient;
2427
import com.google.cloud.compute.v1.GetInstanceRequest;
28+
import com.google.cloud.compute.v1.Image;
29+
import com.google.cloud.compute.v1.ImagesClient;
2530
import com.google.cloud.compute.v1.Instance;
2631
import com.google.cloud.compute.v1.InstanceGroupManager;
2732
import com.google.cloud.compute.v1.InstanceGroupManagersClient;
@@ -37,6 +42,7 @@
3742
import com.google.cloud.compute.v1.ZoneOperationsSettings;
3843
import java.io.IOException;
3944
import java.util.ArrayList;
45+
import java.util.Collections;
4046
import java.util.List;
4147
import java.util.Map;
4248
import org.junit.AfterClass;
@@ -237,6 +243,53 @@ public void testApiError() {
237243
}
238244
}
239245

246+
@Test
247+
public void testInt64() throws IOException {
248+
// we want to test a field with format:int64
249+
String name = generateRandomName("image");
250+
List<Long> licenseCodes = Collections.singletonList(5543610867827062957L);
251+
String sourceImage = "projects/debian-cloud/global/images/debian-10-buster-v20210721";
252+
ImagesClient imagesClient = ImagesClient.create();
253+
Image image =
254+
Image.newBuilder()
255+
.setName(name)
256+
.addAllLicenseCodes(licenseCodes)
257+
.setSourceImage(sourceImage)
258+
.build();
259+
try {
260+
Operation op = imagesClient.insert(DEFAULT_PROJECT, image);
261+
waitGlobalOperation(op);
262+
263+
Image fetched = imagesClient.get(DEFAULT_PROJECT, name);
264+
Assert.assertEquals(licenseCodes, fetched.getLicenseCodesList());
265+
} finally {
266+
imagesClient.delete(DEFAULT_PROJECT, name);
267+
}
268+
}
269+
270+
@Test
271+
public void testCapitalLetterField() throws IOException {
272+
// we want to test a field like "IPProtocol"
273+
String name = generateRandomName("fw-rule");
274+
FirewallsClient firewallsClient = FirewallsClient.create();
275+
Firewall firewall =
276+
Firewall.newBuilder()
277+
.setName(name)
278+
.addAllowed(Allowed.newBuilder().setIPProtocol("tcp").addPorts("80").build())
279+
.addSourceRanges("0.0.0.0/0")
280+
.build();
281+
try {
282+
Operation op = firewallsClient.insert(DEFAULT_PROJECT, firewall);
283+
waitGlobalOperation(op);
284+
285+
Firewall fetched = firewallsClient.get(DEFAULT_PROJECT, name);
286+
Assert.assertEquals(name, fetched.getName());
287+
Assert.assertEquals("tcp", fetched.getAllowed(0).getIPProtocol());
288+
} finally {
289+
firewallsClient.delete(DEFAULT_PROJECT, name);
290+
}
291+
}
292+
240293
@Ignore("Patch is not supported")
241294
@Test
242295
public void testPatch() {

0 commit comments

Comments
 (0)