Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that asserts a successfully inserted instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should be fine for now, and a later PR will test inserting an instance.

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