浏览代码

optimize test case of TestRpcGenerate (#279)

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
songmeizi 4 年之前
父节点
当前提交
b56cc8e459
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      tools/goctl/rpc/generator/gen_test.go

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

@@ -4,6 +4,7 @@ import (
 	"go/build"
 	"go/build"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
+	"strings"
 	"testing"
 	"testing"
 
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/assert"
@@ -44,7 +45,9 @@ func TestRpcGenerate(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Nil(t, err)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	if err != nil {
 	if err != nil {
-		assert.Contains(t, err.Error(), "not in GOROOT")
+		assert.True(t, func() bool {
+			return strings.Contains(err.Error(), "not in GOROOT") || strings.Contains(err.Error(), "cannot find package")
+		}())
 	}
 	}
 
 
 	// case go mod
 	// case go mod
@@ -61,7 +64,9 @@ func TestRpcGenerate(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Nil(t, err)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	if err != nil {
 	if err != nil {
-		assert.Contains(t, err.Error(), "not in GOROOT")
+		assert.True(t, func() bool {
+			return strings.Contains(err.Error(), "not in GOROOT") || strings.Contains(err.Error(), "cannot find package")
+		}())
 	}
 	}
 
 
 	// case not in go mod and go path
 	// case not in go mod and go path
@@ -69,7 +74,9 @@ func TestRpcGenerate(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Nil(t, err)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	_, err = execx.Run("go test "+projectName, projectDir)
 	if err != nil {
 	if err != nil {
-		assert.Contains(t, err.Error(), "not in GOROOT")
+		assert.True(t, func() bool {
+			return strings.Contains(err.Error(), "not in GOROOT") || strings.Contains(err.Error(), "cannot find package")
+		}())
 	}
 	}
 
 
 	// invalid directory
 	// invalid directory