mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 18:00:24 +08:00
e76f44a35b
* reactor rpc generation * update flag * update command * update command * update unit test * delete test file * optimize code * update doc * update gen pb * rename target dir * update mysql data type convert rule * add done flag * optimize req/reply parameter * optimize req/reply parameter * remove waste code * remove duplicate parameter * format code * format code * optimize naming * reactor rpcv2 to rpc * remove new line * format code * rename underline to snake * reactor getParentPackage * remove debug log * reactor background
105 lines
2.3 KiB
Go
105 lines
2.3 KiB
Go
package generator
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
|
)
|
|
|
|
func TestRpcGenerateCaseNilImport(t *testing.T) {
|
|
dispatcher := NewDefaultGenerator()
|
|
if err := dispatcher.Prepare(); err == nil {
|
|
g := NewRpcGenerator(dispatcher)
|
|
abs, err := filepath.Abs("./test")
|
|
assert.Nil(t, err)
|
|
|
|
err = g.Generate("./test_stream.proto", abs, nil)
|
|
defer func() {
|
|
_ = os.RemoveAll(abs)
|
|
}()
|
|
assert.Nil(t, err)
|
|
|
|
_, err = execx.Run("go test "+abs, abs)
|
|
assert.Nil(t, err)
|
|
}
|
|
}
|
|
|
|
func TestRpcGenerateCaseOption(t *testing.T) {
|
|
dispatcher := NewDefaultGenerator()
|
|
if err := dispatcher.Prepare(); err == nil {
|
|
g := NewRpcGenerator(dispatcher)
|
|
abs, err := filepath.Abs("./test")
|
|
assert.Nil(t, err)
|
|
|
|
err = g.Generate("./test_option.proto", abs, nil)
|
|
defer func() {
|
|
_ = os.RemoveAll(abs)
|
|
}()
|
|
assert.Nil(t, err)
|
|
|
|
_, err = execx.Run("go test "+abs, abs)
|
|
assert.Nil(t, err)
|
|
}
|
|
}
|
|
|
|
func TestRpcGenerateCaseWordOption(t *testing.T) {
|
|
dispatcher := NewDefaultGenerator()
|
|
if err := dispatcher.Prepare(); err == nil {
|
|
g := NewRpcGenerator(dispatcher)
|
|
abs, err := filepath.Abs("./test")
|
|
assert.Nil(t, err)
|
|
|
|
err = g.Generate("./test_word_option.proto", abs, nil)
|
|
defer func() {
|
|
_ = os.RemoveAll(abs)
|
|
}()
|
|
assert.Nil(t, err)
|
|
|
|
_, err = execx.Run("go test "+abs, abs)
|
|
assert.Nil(t, err)
|
|
}
|
|
}
|
|
|
|
// test keyword go
|
|
func TestRpcGenerateCaseGoOption(t *testing.T) {
|
|
dispatcher := NewDefaultGenerator()
|
|
if err := dispatcher.Prepare(); err == nil {
|
|
g := NewRpcGenerator(dispatcher)
|
|
abs, err := filepath.Abs("./test")
|
|
assert.Nil(t, err)
|
|
|
|
err = g.Generate("./test_go_option.proto", abs, nil)
|
|
defer func() {
|
|
_ = os.RemoveAll(abs)
|
|
}()
|
|
assert.Nil(t, err)
|
|
|
|
_, err = execx.Run("go test "+abs, abs)
|
|
assert.Nil(t, err)
|
|
}
|
|
}
|
|
|
|
func TestRpcGenerateCaseImport(t *testing.T) {
|
|
dispatcher := NewDefaultGenerator()
|
|
if err := dispatcher.Prepare(); err == nil {
|
|
g := NewRpcGenerator(dispatcher)
|
|
abs, err := filepath.Abs("./test")
|
|
assert.Nil(t, err)
|
|
|
|
err = g.Generate("./test_import.proto", abs, []string{"./base"})
|
|
defer func() {
|
|
_ = os.RemoveAll(abs)
|
|
}()
|
|
assert.Nil(t, err)
|
|
|
|
_, err = execx.Run("go test "+abs, abs)
|
|
assert.True(t, func() bool {
|
|
return strings.Contains(err.Error(), "package base is not in GOROOT")
|
|
}())
|
|
}
|
|
}
|