Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(google): Add partner metadata on instanceTemplate properties (backport #6334) #6335

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
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 @@ -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,
Expand Down Expand Up @@ -65,7 +67,11 @@ public PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate>
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

ImmutableList<InstanceTemplate> 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<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

ImmutableList<InstanceTemplate> 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<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

assertThatIOException().isThrownBy(() -> request.execute());
}

private static InstanceTemplates createInstanceTemplates(HttpTransport transport) {
return createInstanceTemplates(transport, new NoopRegistry());
}
Expand Down
Loading