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

chore: Add HttpJson Showcase test for Location Mixins #1656

Merged
merged 9 commits into from
Apr 28, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
name: ci
env:
SHOWCASE_VERSION: 0.26.1
SHOWCASE_VERSION: 0.27.0
jobs:
build:
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SonarCloud Build
env:
SHOWCASE_VERSION: 0.26.1
SHOWCASE_VERSION: 0.27.0
Copy link
Member

@burkedavison burkedavison Apr 27, 2023

Choose a reason for hiding this comment

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

Five version update locations. Oof. We should find a way to refactor this to reduce the chance we miss one in the future.

Edit: To be clear, not requesting this change in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, agreed. Created an issue about automating the showcase version (#1601), but also worth looking into refactoring so that the version is managed in one place.

on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/presubmit/downstream-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

set -eo pipefail

SHOWCASE_VERSION=0.26.1
SHOWCASE_VERSION=0.27.0

## Get the directory of the build script
scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
Expand Down
2 changes: 1 addition & 1 deletion showcase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ versions is not guaranteed. If changing the version of the server, it may also b
update to a compatible client version in `./WORKSPACE`.

```shell
$ GAPIC_SHOWCASE_VERSION=0.26.1
$ GAPIC_SHOWCASE_VERSION=0.27.0
$ go install github.com/googleapis/gapic-showcase/cmd/gapic-showcase@v"$GAPIC_SHOWCASE_VERSION"
$ PATH=$PATH:`go env GOPATH`/bin
$ gapic-showcase --help
Expand Down
2 changes: 1 addition & 1 deletion showcase/gapic-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<properties>
<gapic-showcase.version>0.26.1</gapic-showcase.version>
<gapic-showcase.version>0.27.0</gapic-showcase.version>
</properties>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,49 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.Location;
import com.google.common.collect.ImmutableList;
import com.google.showcase.v1beta1.EchoClient;
import com.google.showcase.v1beta1.EchoSettings;
import io.grpc.ManagedChannelBuilder;
import java.io.IOException;
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

public class ITCommonServiceMixins {

// The showcase server always returns a fixed list of locations. See
// https://github.com/googleapis/gapic-showcase/blob/main/server/services/locations_service.go
private static final List<Location> EXPECTED_LOCATIONS =
ImmutableList.of(
Location.newBuilder()
.setName("projects/showcase/locations/us-north")
.setDisplayName("us-north")
.build(),
Location.newBuilder()
.setName("projects/showcase/locations/us-south")
.setDisplayName("us-south")
.build(),
Location.newBuilder()
.setName("projects/showcase/locations/us-east")
.setDisplayName("us-east")
.build(),
Location.newBuilder()
.setName("projects/showcase/locations/us-west")
.setDisplayName("us-west")
.build());
private EchoClient grpcClient;
private EchoClient httpjsonClient;

@Before
public void createClients() throws IOException {
public void createClients() throws Exception {
// Create gRPC Echo Client
EchoSettings grpcEchoSettings =
EchoSettings.newBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build())
.build();
grpcClient = EchoClient.create(grpcEchoSettings);
grpcClient = TestClientInitializer.createGrpcEchoClient();

// Create HttpJson Echo Client
httpjsonClient = TestClientInitializer.createHttpJsonEchoClient();
}

@Test
Expand All @@ -69,36 +83,39 @@ public void testGrpc_listLocations() {
EchoClient.ListLocationsPagedResponse locationsPagedResponse =
grpcClient.listLocations(request);

// The showcase server always returns a fixed list of locations. See
// https://github.com/googleapis/gapic-showcase/blob/main/server/services/locations_service.go
ArrayList<Location> actualLocations = new ArrayList<>();
List<Location> actualLocations = new ArrayList<>();
for (Location location : locationsPagedResponse.iterateAll()) {
actualLocations.add(location);
}

assertThat(actualLocations).containsExactlyElementsIn(EXPECTED_LOCATIONS).inOrder();
}

@Test
public void testHttpJson_getLocation() {
GetLocationRequest request =
GetLocationRequest.newBuilder().setName("projects/showcase/locations/us-central1").build();
Location location = httpjsonClient.getLocation(request);
assertThat(location)
.isEqualTo(
Location.newBuilder()
.setName("projects/showcase/locations/us-central1")
.setDisplayName("us-central1")
.build());
}

@Test
public void testHttpJson_listLocations() {
ListLocationsRequest request =
ListLocationsRequest.newBuilder().setName("projects/showcase").build();
EchoClient.ListLocationsPagedResponse locationsPagedResponse =
httpjsonClient.listLocations(request);

List<Location> actualLocations = new ArrayList<>();
for (Location location : locationsPagedResponse.iterateAll()) {
actualLocations.add(location);
}
Location locationUsNorth =
Location.newBuilder()
.setName("projects/showcase/locations/us-north")
.setDisplayName("us-north")
.build();
Location locationUsSouth =
Location.newBuilder()
.setName("projects/showcase/locations/us-south")
.setDisplayName("us-south")
.build();
Location locationUsEast =
Location.newBuilder()
.setName("projects/showcase/locations/us-east")
.setDisplayName("us-east")
.build();
Location locationUsWest =
Location.newBuilder()
.setName("projects/showcase/locations/us-west")
.setDisplayName("us-west")
.build();

assertThat(actualLocations)
.containsExactlyElementsIn(
ImmutableList.of(locationUsNorth, locationUsSouth, locationUsEast, locationUsWest))
.inOrder();
assertThat(actualLocations).containsExactlyElementsIn(EXPECTED_LOCATIONS).inOrder();
}
}