From c88a1838b0a4c9933877240c8ec07f7e1dbdc52b Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 28 Jun 2023 16:12:59 -0700 Subject: [PATCH 1/2] test(showcase): add script to test against local showcase repo This is useful during Showcase development. --- showcase/README.md | 23 +++++++++--- showcase/showcase-local.sh | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 showcase/showcase-local.sh diff --git a/showcase/README.md b/showcase/README.md index e420869d0..93c7a10e6 100644 --- a/showcase/README.md +++ b/showcase/README.md @@ -5,14 +5,17 @@ gapic-generator-go, as well as the script used to setup and execute them. ## How the tests work +### Testing the released Showcase GAPIC client The tests can be run out-of-the-box in the normal `go test` fashion, so long as there is a `gapic-showcase` server already running locally. This does not test the Showcase client generated with the locally installed generator - it would -use the released version of the GAPIC. Running `make test` (from the repository -root) will execute the tests against the locally installed generator. +use the released version of the GAPIC. -To test the local generator, use the `showcase.bash` script. It does the -following: +### Testing client locally generated from published Showcase repo +Running `make test` (from the repository root) will execute the tests against +the locally installed generator. It installs the generator locally and then +calls the `showcase.bash` script to test the local generator. The script does +the following: 1. Downloads the Showcase artifacts associated with the targeted version. These are the compiled proto descriptor set, the retry configuration, and a @@ -20,8 +23,10 @@ pre-compiled server binary. 1. Using protoc and the retrieved artifacts as input, the Go protobuf/gRPC bindings, and the Go GAPIC are generated, the latter with the **locally -installed** gapic-generator-go. Make sure to `make install` (from the repository -root) so that any new changes are utilized during generation. +installed** gapic-generator-go. If invoking the script directly, make sure to +`make install` (from the repository root) so that any new changes are utilized +during generation; if invoking the script via `make test`, this will +automatically happen. 1. The submodule's `go.mod` is temporarily edited to replace the remote dependency on `github.com/googleapis/gapic-showcase` with the locally generated @@ -33,6 +38,12 @@ artifacts. 1. The server process is stopped. +### Testing client locally generated from local Showcase repo +During development, it may sometimes be necessary to run the Go Showcase tests +against a local version of Showcase with pending changes that are not yet in the +[googleapis/gapic-showcase](https://github.com/googleapis/gapic-showcase/releases/tag/v0.28.1) +repository. To do that, refer to [showcase-local.sh](./showcase-local.sh). + ### Adding tests Adding tests for an existing service is as easy as adding a new Go test to the diff --git a/showcase/showcase-local.sh b/showcase/showcase-local.sh new file mode 100644 index 000000000..c76b67e5f --- /dev/null +++ b/showcase/showcase-local.sh @@ -0,0 +1,76 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# To run the gapic-generator-go Showcase tests using a local version of Showcase +# (eg in development), set the following variables before calling the +# test-with-local-showcase function below. + +GO_GENERATOR="$(pwd)/.." +API_COMMON_PROTOS="" # path to local version of api-common-protos +LOCAL_SHOWCASE_REPO="" # path to local version of gapic-showcase + +test-with-local-showcase(){ + + [[ -n "${GO_GENERATOR}" ]] || { echo '${GO_GENERATOR} must be set' ; return 1 ; } + [[ -n "${API_COMMON_PROTOS}" ]] || { echo '${API_COMMON_PROTOS} must be set' ; return 1 ; } + [[ -n "${LOCAL_SHOWCASE_REPO}" ]] || { echo '${LOCAL_SHOWCASE_REPO} must be set' ; return 1 ; } + + GO_GENERATOR="$(realpath ${GO_GENERATOR})" + API_COMMON_PROTOS="$(realpath ${API_COMMON_PROTOS})" + LOCAL_SHOWCASE_REPO="$(realpath ${LOCAL_SHOWCASE_REPO})" + SHOWCASE_SCHEMA="${LOCAL_SHOWCASE_REPO}/schema/google/showcase/v1beta1" + + + cat <& /dev/null + go install ./cmd/protoc-gen-go_gapic + + cd showcase + + GAPIC_OUT_DIR="./gen" + rm -rf $GAPIC_OUT_DIR + mkdir -p $GAPIC_OUT_DIR + protoc --experimental_allow_proto3_optional -I $API_COMMON_PROTOS \ + --go_gapic_out $GAPIC_OUT_DIR \ + --go_gapic_opt 'transport=rest+grpc' \ + --go_gapic_opt 'rest-numeric-enums' \ + --go_gapic_opt='go-gapic-package=github.com/googleapis/gapic-showcase/client;client' \ + --go_gapic_opt=grpc-service-config=${SHOWCASE_SCHEMA}/showcase_grpc_service_config.json \ + --go_gapic_opt=api-service-config=${SHOWCASE_SCHEMA}/showcase_v1beta1.yaml \ + $PLUGIN --proto_path=$SHOWCASE_SCHEMA $SHOWCASE_SCHEMA/*.proto + + go mod edit -replace=github.com/googleapis/gapic-showcase=./gen/github.com/googleapis/gapic-showcase + + pushd ./gen/github.com/googleapis/gapic-showcase >& /dev/null + go mod init gapic-showcase + mkdir server + ln -s ${LOCAL_SHOWCASE_REPO}/server/genproto server/ + popd >& /dev/null + + # ensure your Showcase server is running + + cp ${LOCAL_SHOWCASE_REPO}/server/services/compliance_suite.json . + go test -mod=mod -count=1 ./... + + popd >& /dev/null +} + +test-with-local-showcase From e5081ecdbfd0e3b2ecd8649e9b68b70db8cef29d Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 28 Jun 2023 16:21:46 -0700 Subject: [PATCH 2/2] tweak wording --- showcase/showcase-local.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/showcase/showcase-local.sh b/showcase/showcase-local.sh index c76b67e5f..a1361d169 100644 --- a/showcase/showcase-local.sh +++ b/showcase/showcase-local.sh @@ -16,9 +16,9 @@ # (eg in development), set the following variables before calling the # test-with-local-showcase function below. -GO_GENERATOR="$(pwd)/.." -API_COMMON_PROTOS="" # path to local version of api-common-protos -LOCAL_SHOWCASE_REPO="" # path to local version of gapic-showcase +GO_GENERATOR="$(pwd)/.." # path to local clone of gapic-generator-go +API_COMMON_PROTOS="" # path to local clone of api-common-protos +LOCAL_SHOWCASE_REPO="" # path to local clone of gapic-showcase test-with-local-showcase(){