Skip to content

Commit 4304f91

Browse files
committed
Refine go test
1 parent 220c30e commit 4304f91

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@
6767

6868
## 如何参与项目
6969

70-
* 写测试 Writing test
71-
* 代码审查 Code review
72-
* 添加新的template
70+
### 写测试 Writing test
71+
72+
#### go test
73+
74+
* 先完成编译`go build`
75+
* 将编译出来的可执行文件设置到`PROTOAPI_EXE`环境变量
76+
* 再执行`go test`
77+
78+
### 代码审查 Code review
79+
7380

7481
### 添加新的template
7582

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func main() {
3434

3535
// when no any parameter and not reading from char device, treat it as being called by protoc
3636
if len(args) == 1 && err == nil && (stat.Mode()&os.ModeCharDevice) == 0 {
37+
// check for PROTOAPI_PORT, if set means it's in go test
3738
protoapiPort := os.Getenv("PROTOAPI_PORT")
3839
if protoapiPort != "" {
3940
resp, err := http.Post("http://127.0.0.1:"+protoapiPort+"/", "application/protobuf", os.Stdin)
@@ -63,7 +64,6 @@ func main() {
6364
util.Die(err)
6465
}
6566
} else {
66-
go serv()
6767
cmd.Execute()
6868
}
6969
}

main_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ func test(t *testing.T, args string) {
4040
}
4141

4242
func TestCmd(t *testing.T) {
43+
executable := os.Getenv("PROTOAPI_EXE")
44+
if executable == "" {
45+
t.Error("PROTOAPI_EXE is not set")
46+
return
47+
}
48+
4349
test(t, "gen --lang=go test/result/go test/proto/test.proto")
4450
// test(t, "gen --lang=go test/result/go test/proto/calc.proto")
4551
// test(t, "gen --lang=go test/result/go test/proto/todolist.proto")

test/result/go/.keep

Whitespace-only changes.

test/result/ts/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)