Skip to content

Commit

Permalink
Add ITComputeTest test for resource name (googleapis#4417)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamlin authored Feb 22, 2019
1 parent 4aef34d commit 6300b45
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package com.google.cloud.compute.v1.it;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.fail;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.paging.Page;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
Expand All @@ -27,10 +29,14 @@
import com.google.cloud.compute.v1.DiskTypeClient.AggregatedListDiskTypesPagedResponse;
import com.google.cloud.compute.v1.DiskTypeSettings;
import com.google.cloud.compute.v1.DiskTypesScopedList;
import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstanceClient;
import com.google.cloud.compute.v1.InstanceSettings;
import com.google.cloud.compute.v1.ListDiskTypesHttpRequest;
import com.google.cloud.compute.v1.ProjectName;
import com.google.cloud.compute.v1.ProjectRegionDiskTypeName;
import com.google.cloud.compute.v1.ProjectZoneDiskTypeName;
import com.google.cloud.compute.v1.ProjectZoneMachineTypeName;
import com.google.cloud.compute.v1.ProjectZoneName;
import com.google.common.collect.Lists;
import java.io.IOException;
Expand All @@ -52,6 +58,9 @@ public class ITComputeTest {
private static DiskTypeClient diskTypeClient;
private static DiskTypeSettings diskTypeSettings;

private static InstanceClient instanceClient;
private static InstanceSettings instanceSettings;

@Rule public Timeout globalTimeout = Timeout.seconds(300);

@BeforeClass
Expand All @@ -65,11 +74,18 @@ public static void beforeClass() throws IOException {
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
diskTypeClient = DiskTypeClient.create(diskTypeSettings);

instanceSettings =
InstanceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
instanceClient = InstanceClient.create(instanceSettings);
}

@AfterClass
public static void tearDown() throws Exception {
diskTypeClient.close();
instanceClient.close();
}

@Test
Expand All @@ -85,6 +101,26 @@ public void testGetDiskType() {
assertThat(diskType.getDefaultDiskSizeGb()).isNotNull();
}

@Test
public void testInsertInstance() {
String machineType =
ProjectZoneMachineTypeName.of("n1-standard-1", DEFAULT_PROJECT, ZONE).toString();
Instance instance =
Instance.newBuilder().setName("mytestinstancetemplate").setMachineType(machineType).build();
try {
instanceClient.insertInstance(ProjectZoneName.of(DEFAULT_PROJECT, ZONE), instance);
} catch (InvalidArgumentException e) {
// Expect a Bad Request HTTP 400 error, but it should NOT be because of a resource name
// problem.
assertThat(e.getMessage()).contains("Bad Request");
assertThat(e.getCause().getMessage())
.contains("Invalid value for field 'resource.networkInterfaces'");
return;
}

fail("Expected HTTP Bad Request to be returned, but it was not returned.");
}

@Test
public void testListDiskTypes() {
Page<DiskType> diskPage =
Expand Down

0 comments on commit 6300b45

Please sign in to comment.