feat: Remove command goctl rpc proto (#1665)
* Fix goctl completion expression * Fix code generation error if the pkg of pb/grpc is same to zrpc call client pkg * Remove deprecated comment on action goctl rpc new * Remove zrpc code generation on action goctl rpc proto * Remove zrpc code generation on action goctl rpc proto * Remove Generator interface Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -10,26 +11,19 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
conf "github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
var cfg = &conf.Config{
|
||||
NamingFormat: "gozero",
|
||||
}
|
||||
|
||||
func TestRpcGenerate(t *testing.T) {
|
||||
_ = Clean()
|
||||
dispatcher := NewDefaultGenerator()
|
||||
err := dispatcher.Prepare()
|
||||
g := NewGenerator("gozero")
|
||||
err := g.Prepare()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
projectName := stringx.Rand()
|
||||
g := NewRPCGenerator(dispatcher, cfg)
|
||||
|
||||
src := filepath.Join(build.Default.GOPATH, "src")
|
||||
_, err = os.Stat(src)
|
||||
if err != nil {
|
||||
@@ -46,7 +40,15 @@ func TestRpcGenerate(t *testing.T) {
|
||||
|
||||
// case go path
|
||||
t.Run("GOPATH", func(t *testing.T) {
|
||||
err = g.Generate("./test.proto", projectDir, []string{common}, "Mbase/common.proto=./base")
|
||||
ctx := &ZRpcContext{
|
||||
Src: "./test.proto",
|
||||
ProtocCmd: fmt.Sprintf("protoc -I=%s test.proto --go_out=%s --go_opt=Mbase/common.proto=./base --go-grpc_out=%s", common, projectDir, projectDir),
|
||||
IsGooglePlugin: true,
|
||||
GoOutput: projectDir,
|
||||
GrpcOutput: projectDir,
|
||||
Output: projectDir,
|
||||
}
|
||||
err = g.Generate(ctx)
|
||||
assert.Nil(t, err)
|
||||
_, err = execx.Run("go test "+projectName, projectDir)
|
||||
if err != nil {
|
||||
@@ -67,7 +69,15 @@ func TestRpcGenerate(t *testing.T) {
|
||||
}
|
||||
|
||||
projectDir = filepath.Join(workDir, projectName)
|
||||
err = g.Generate("./test.proto", projectDir, []string{common}, "Mbase/common.proto=./base")
|
||||
ctx := &ZRpcContext{
|
||||
Src: "./test.proto",
|
||||
ProtocCmd: fmt.Sprintf("protoc -I=%s test.proto --go_out=%s --go_opt=Mbase/common.proto=./base --go-grpc_out=%s", common, projectDir, projectDir),
|
||||
IsGooglePlugin: true,
|
||||
GoOutput: projectDir,
|
||||
GrpcOutput: projectDir,
|
||||
Output: projectDir,
|
||||
}
|
||||
err = g.Generate(ctx)
|
||||
assert.Nil(t, err)
|
||||
_, err = execx.Run("go test "+projectName, projectDir)
|
||||
if err != nil {
|
||||
@@ -79,7 +89,15 @@ func TestRpcGenerate(t *testing.T) {
|
||||
|
||||
// case not in go mod and go path
|
||||
t.Run("OTHER", func(t *testing.T) {
|
||||
err = g.Generate("./test.proto", projectDir, []string{common, src}, "Mbase/common.proto=./base")
|
||||
ctx := &ZRpcContext{
|
||||
Src: "./test.proto",
|
||||
ProtocCmd: fmt.Sprintf("protoc -I=%s test.proto --go_out=%s --go_opt=Mbase/common.proto=./base --go-grpc_out=%s", common, projectDir, projectDir),
|
||||
IsGooglePlugin: true,
|
||||
GoOutput: projectDir,
|
||||
GrpcOutput: projectDir,
|
||||
Output: projectDir,
|
||||
}
|
||||
err = g.Generate(ctx)
|
||||
assert.Nil(t, err)
|
||||
_, err = execx.Run("go test "+projectName, projectDir)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user