Skip to content

Commit 1dd0ec5

Browse files
authored
Add tests for go and validator source relative flags (namely#223)
1 parent 5b89a83 commit 1dd0ec5

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

all/test.sh

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ testGeneration() {
2929

3030
if [[ "$lang" == "go" ]]; then
3131
# Test that we have generated the test.pb.go file.
32-
expected_file_name="/all/test/test.pb.go"
32+
expected_file_name="/all/test.pb.go"
33+
if [[ "$extra_args" == *"--go-source-relative"* ]]; then
34+
expected_file_name="/all/test/test.pb.go"
35+
fi
3336
if [[ ! -f "$expected_output_dir$expected_file_name" ]]; then
3437
echo "$expected_file_name file was not generated in $expected_output_dir"
3538
exit 1
@@ -66,7 +69,7 @@ testGeneration() {
6669

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

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

107+
# Test that we have generated the test.pb.go file.
108+
expected_file_name="/all/test.pb.go"
109+
if [[ "$extra_args" == *"--with-validator"* ]]; then
110+
expected_file_name1="/all/test.pb.go"
111+
expected_file_name2="/all/test.pb.validate.go"
112+
if [[ "$extra_args" == *"--validator-source-relative"* ]]; then
113+
expected_file_name2="/all/test/test.pb.validate.go"
114+
fi
115+
if [[ ! -f "$expected_output_dir$expected_file_name1" ]]; then
116+
echo "$expected_file_name1 file was not generated in $expected_output_dir"
117+
exit 1
118+
fi
119+
if [[ ! -f "$expected_output_dir$expected_file_name2" ]]; then
120+
echo "$expected_file_name2 file was not generated in $expected_output_dir"
121+
exit 1
122+
fi
123+
fi
124+
104125
rm -rf `echo $expected_output_dir | cut -d '/' -f1`
105126
echo "Generating for $lang passed!"
106127
}
@@ -114,6 +135,15 @@ testGeneration go "gen/pb-go" --with-gateway --with-openapi-json-names
114135
# Test grpc-gateway generation + json (deprecated) (only valid for Go)
115136
testGeneration go "gen/pb-go" --with-gateway --with-swagger-json-names
116137

138+
# Test go source relative generation
139+
testGeneration go "gen/pb-go" --go-source-relative
140+
141+
# Test go validator
142+
testGeneration go "gen/pb-go" --with-validator
143+
144+
# Test go validator with source relative option
145+
testGeneration go "gen/pb-go" --with-validator --validator-source-relative
146+
117147
# Test go-micro generations
118148
testGeneration go "gen/pb-go" --go-plugin-micro
119149

all/test/include.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ syntax = "proto3";
22

33
package Messages;
44

5-
option go_package = "all/test";
5+
option go_package = "all;all";
66

77
message ListMessageResponse {
88
repeated string messages = 1;

all/test/test.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "all/test/include.proto";
55

66
package Messages;
77

8-
option go_package = "all/test";
8+
option go_package = "all;all";
99

1010
service Message {
1111
rpc ListMessage (ListMessageRequest) returns (ListMessageResponse) {

0 commit comments

Comments
 (0)