Skip to content

Commit

Permalink
test(showcase): add script to test against local showcase repo
Browse files Browse the repository at this point in the history
This is useful during Showcase development.
  • Loading branch information
vchudnov-g committed Jun 28, 2023
1 parent 7a05e8d commit c88a183
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 6 deletions.
23 changes: 17 additions & 6 deletions showcase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ 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
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
Expand All @@ -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
Expand Down
76 changes: 76 additions & 0 deletions showcase/showcase-local.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Running with:
GO_GENERATOR: ${GO_GENERATOR}
API_COMMON_PROTOS: ${API_COMMON_PROTOS}
LOCAL_SHOWCASE_REPO: ${LOCAL_SHOWCASE_REPO}
EOF


pushd "${GO_GENERATOR}" >& /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

0 comments on commit c88a183

Please sign in to comment.