diff --git a/clouddriver-google/src/main/java/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplates.java b/clouddriver-google/src/main/java/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplates.java index c1f3c265934..518e2bb3fd3 100644 --- a/clouddriver-google/src/main/java/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplates.java +++ b/clouddriver-google/src/main/java/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplates.java @@ -29,6 +29,8 @@ public class InstanceTemplates { private final Compute.InstanceTemplates computeApi; private final GoogleNamedAccountCredentials credentials; private final GlobalGoogleComputeRequestFactory requestFactory; + private static final String defaultView = + "FULL"; // https://cloud.google.com/sdk/gcloud/reference/beta/compute/instance-templates/list InstanceTemplates( GoogleNamedAccountCredentials credentials, @@ -65,7 +67,11 @@ public PaginatedComputeRequest return new PaginatedComputeRequestImpl<>( pageToken -> requestFactory.wrapRequest( - computeApi.list(credentials.getProject()).setPageToken(pageToken), "list"), + computeApi + .list(credentials.getProject()) + .setPageToken(pageToken) + .setView(defaultView), + "list"), InstanceTemplateList::getNextPageToken, InstanceTemplateList::getItems); } diff --git a/clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplatesTest.java b/clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplatesTest.java index 1f1550737ec..372b680b5f3 100644 --- a/clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplatesTest.java +++ b/clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/compute/InstanceTemplatesTest.java @@ -25,6 +25,7 @@ import com.google.api.client.testing.http.MockLowLevelHttpResponse; import com.google.api.services.compute.Compute; import com.google.api.services.compute.model.InstanceTemplate; +import com.google.common.collect.ImmutableList; import com.netflix.spectator.api.BasicTag; import com.netflix.spectator.api.DefaultRegistry; import com.netflix.spectator.api.NoopRegistry; @@ -190,6 +191,69 @@ public void get_errorMetrics() { assertThat(timer.totalTime()).isEqualTo(CLOCK_STEP_TIME_NS); } + @Test + public void list_success() throws IOException { + + MockHttpTransport transport = + new MockHttpTransport.Builder() + .setLowLevelHttpResponse( + new MockLowLevelHttpResponse() + .setStatusCode(200) + .addHeader("Content-Type", "application/json") + .setContent( + "{\"items\": [{\"name\": \"template1\"}, {\"name\": \"template2\"}], \"nextPageToken\": \"\"}")) + .build(); + + InstanceTemplates instanceTemplates = createInstanceTemplates(transport); + + PaginatedComputeRequest request = + instanceTemplates.list(); + + ImmutableList response = request.execute(); + assertThat(response).hasSize(2); + assertThat(response.get(0).getName()).isEqualTo("template1"); + assertThat(response.get(1).getName()).isEqualTo("template2"); + } + + @Test + public void list_noResults() throws IOException { + + MockHttpTransport transport = + new MockHttpTransport.Builder() + .setLowLevelHttpResponse( + new MockLowLevelHttpResponse() + .setStatusCode(200) + .setContent("{\"items\": [], \"nextPageToken\": \"\"}")) + .build(); + + InstanceTemplates instanceTemplates = createInstanceTemplates(transport); + + PaginatedComputeRequest request = + instanceTemplates.list(); + + ImmutableList response = request.execute(); + assertThat(response).isEmpty(); + } + + @Test + public void list_errorResponse() { + + MockHttpTransport transport = + new MockHttpTransport.Builder() + .setLowLevelHttpResponse( + new MockLowLevelHttpResponse() + .setStatusCode(500) + .setContent("{\"error\": \"Internal Server Error\"}")) + .build(); + + InstanceTemplates instanceTemplates = createInstanceTemplates(transport); + + PaginatedComputeRequest request = + instanceTemplates.list(); + + assertThatIOException().isThrownBy(() -> request.execute()); + } + private static InstanceTemplates createInstanceTemplates(HttpTransport transport) { return createInstanceTemplates(transport, new NoopRegistry()); }