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

cmd/protoc-gen-go-grpc: add change detector test #7072

Merged
merged 23 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ jobs:
interop/interop_test.sh
echo -e "\n-- Running xDS E2E Test --"
xds/internal/test/e2e/run.sh
echo -e "\n-- Running protoc-gen-go-grpc test --"
./scripts/vet-proto.sh -install
cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ change from the grpc code generator previously included with `protoc-gen-go`.
To restore this behavior, set the option `require_unimplemented_servers=false`.
E.g.:

```
```sh
protoc --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false[,other options...] \
```

Expand Down
48 changes: 48 additions & 0 deletions cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash -e

# Copyright 2024 gRPC authors.
#
# 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
#
# http://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.

# Uncomment to enable debugging.
# set -x

WORKDIR="$(dirname $0)"
TEMPDIR=$(mktemp -d)

trap "rm -rf ${TEMPDIR}" EXIT

# Build protoc-gen-go-grpc binary and add to $PATH.
pushd "${WORKDIR}"
go build -o "${TEMPDIR}" .
PATH="${TEMPDIR}:${PATH}"
popd

protoc1 \
--go-grpc_out="${TEMPDIR}" \
--go-grpc_opt=paths=source_relative \
"$WORKDIR/testdata/golden.proto"

GOLDENFILE="${WORKDIR}/testdata/golden_grpc.pb.go"
GENFILE="${TEMPDIR}/cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go"

DIFF=$(diff "${GOLDENFILE}" "${GENFILE}")
if [[ -n "${DIFF}" ]]; then
echo -e "ERROR: Generated file golden_grpc.pb.go differs from golden file:\n${DIFF}"
echo -e "If you have made recent changes to protoc-gen-go-grpc," \
"please regenerate the golden files by running:" \
"\n\t go generate google.golang.org/grpc/..." >&2
exit 1
fi

echo SUCCESS
249 changes: 249 additions & 0 deletions cmd/protoc-gen-go-grpc/testdata/golden.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions cmd/protoc-gen-go-grpc/testdata/golden.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 gRPC authors.
//
// 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
//
// http://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.

syntax = "proto3";

option go_package = "google.golang.org/grpc/cmd/protoc-gen-go-grpc/testdata";

package main;

message EventRequest {
bytes content = 1;
}

message EventResponse {
bytes content = 1;
}

service BidirectionalStreamingService {
rpc unaryMethod(EventRequest) returns (EventResponse) {}
rpc clientMethod(stream EventRequest) returns (EventResponse) {}
rpc serverMethod(EventRequest) returns (stream EventResponse) {};
rpc bidirectionalMethod(stream EventRequest) returns (stream EventResponse) {}
}
Loading
Loading