Skip to content

Commit

Permalink
Add tests for go and validator source relative flags (namely#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-namely authored Dec 11, 2020
1 parent 5b89a83 commit 1dd0ec5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
36 changes: 33 additions & 3 deletions all/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ testGeneration() {

if [[ "$lang" == "go" ]]; then
# Test that we have generated the test.pb.go file.
expected_file_name="/all/test/test.pb.go"
expected_file_name="/all/test.pb.go"
if [[ "$extra_args" == *"--go-source-relative"* ]]; then
expected_file_name="/all/test/test.pb.go"
fi
if [[ ! -f "$expected_output_dir$expected_file_name" ]]; then
echo "$expected_file_name file was not generated in $expected_output_dir"
exit 1
Expand Down Expand Up @@ -66,7 +69,7 @@ testGeneration() {

if [[ "$extra_args" == *"--go-plugin-micro"* ]]; then
# Test that we have generated the test.pb.micro.go file.
expected_file_name="/all/test/test.pb.micro.go"
expected_file_name="/all/test.pb.micro.go"
if [[ ! -f "$expected_output_dir$expected_file_name" ]]; then
echo "$expected_file_name file was not generated in $expected_output_dir"
exit 1
Expand All @@ -75,7 +78,7 @@ testGeneration() {

if [[ "$extra_args" == *"--with-gateway"* ]]; then
# Test that we have generated the test.pb.gw.go file.
expected_file_name1="/all/test/test.pb.gw.go"
expected_file_name1="/all/test.pb.gw.go"
expected_file_name2="/all/test/test.swagger.json"
if [[ ! -f "$expected_output_dir$expected_file_name1" ]]; then
echo "$expected_file_name1 file was not generated in $expected_output_dir"
Expand All @@ -101,6 +104,24 @@ testGeneration() {
fi
fi

# Test that we have generated the test.pb.go file.
expected_file_name="/all/test.pb.go"
if [[ "$extra_args" == *"--with-validator"* ]]; then
expected_file_name1="/all/test.pb.go"
expected_file_name2="/all/test.pb.validate.go"
if [[ "$extra_args" == *"--validator-source-relative"* ]]; then
expected_file_name2="/all/test/test.pb.validate.go"
fi
if [[ ! -f "$expected_output_dir$expected_file_name1" ]]; then
echo "$expected_file_name1 file was not generated in $expected_output_dir"
exit 1
fi
if [[ ! -f "$expected_output_dir$expected_file_name2" ]]; then
echo "$expected_file_name2 file was not generated in $expected_output_dir"
exit 1
fi
fi

rm -rf `echo $expected_output_dir | cut -d '/' -f1`
echo "Generating for $lang passed!"
}
Expand All @@ -114,6 +135,15 @@ testGeneration go "gen/pb-go" --with-gateway --with-openapi-json-names
# Test grpc-gateway generation + json (deprecated) (only valid for Go)
testGeneration go "gen/pb-go" --with-gateway --with-swagger-json-names

# Test go source relative generation
testGeneration go "gen/pb-go" --go-source-relative

# Test go validator
testGeneration go "gen/pb-go" --with-validator

# Test go validator with source relative option
testGeneration go "gen/pb-go" --with-validator --validator-source-relative

# Test go-micro generations
testGeneration go "gen/pb-go" --go-plugin-micro

Expand Down
2 changes: 1 addition & 1 deletion all/test/include.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package Messages;

option go_package = "all/test";
option go_package = "all;all";

message ListMessageResponse {
repeated string messages = 1;
Expand Down
2 changes: 1 addition & 1 deletion all/test/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "all/test/include.proto";

package Messages;

option go_package = "all/test";
option go_package = "all;all";

service Message {
rpc ListMessage (ListMessageRequest) returns (ListMessageResponse) {
Expand Down

0 comments on commit 1dd0ec5

Please sign in to comment.