ソースを参照

optimize unit test (#999)

anqiansong 3 年 前
コミット
84d2b64e7c

+ 3 - 2
tools/goctl/rpc/generator/gen_test.go

@@ -8,6 +8,7 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
+
 	"github.com/tal-tech/go-zero/core/logx"
 	"github.com/tal-tech/go-zero/core/stringx"
 	conf "github.com/tal-tech/go-zero/tools/goctl/config"
@@ -45,7 +46,7 @@ func TestRpcGenerate(t *testing.T) {
 
 	// case go path
 	t.Run("GOPATH", func(t *testing.T) {
-		err = g.Generate("./test.proto", projectDir, []string{common, src}, "Mbase/common.proto=./base")
+		err = g.Generate("./test.proto", projectDir, []string{common}, "Mbase/common.proto=./base")
 		assert.Nil(t, err)
 		_, err = execx.Run("go test "+projectName, projectDir)
 		if err != nil {
@@ -66,7 +67,7 @@ func TestRpcGenerate(t *testing.T) {
 		}
 
 		projectDir = filepath.Join(workDir, projectName)
-		err = g.Generate("./test.proto", projectDir, []string{common, src}, "Mbase/common.proto=./base")
+		err = g.Generate("./test.proto", projectDir, []string{common}, "Mbase/common.proto=./base")
 		assert.Nil(t, err)
 		_, err = execx.Run("go test "+projectName, projectDir)
 		if err != nil {

+ 0 - 3
tools/goctl/rpc/generator/test.proto

@@ -4,14 +4,11 @@ syntax = "proto3";
 package test;
 
 import "base/common.proto";
-import "google/protobuf/any.proto";
-
 option go_package = "github.com/test";
 
 message Req {
   string in = 1;
   common.User user = 2;
-  google.protobuf.Any object = 4;
 }
 
 message Reply {

+ 7 - 2
tools/goctl/util/path.go

@@ -121,8 +121,13 @@ func ReadLink(name string) (string, error) {
 		return "", err
 	}
 
-	if name == "/" {
-		return "/", nil
+	if _, err := os.Lstat(name); err != nil {
+		return name, nil
+	}
+
+	// uncheck condition: ignore file path /var, maybe be temporary file path
+	if name == "/" || name == "/var" {
+		return name, nil
 	}
 
 	isLink, err := isLink(name)