-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spi添加 #258
spi添加 #258
Conversation
spi/user_service/a.go
Outdated
@@ -0,0 +1,25 @@ | |||
// Copyright 2021 ecodeclub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 既然user_service目录和user_service2目录只在测试中使用, 将其移动到/spi/testdata中, 研究一下go中testdata的用法.
- 选择使用go plugin方法实现,需要添加readme,或者Example来一步一步指导用户如何使用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 按照 testdata 的用法修改
- 写一个简单的 Example 就可以
spi/spi_test.go
Outdated
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_LoadService(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加 setupTest方法, 示例如下:
func setupTest(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)
cmd := exec.Command("go", "generate", "./...")
cmd.Dir = filepath.Join(wd, "testdata")
output, err := cmd.CombinedOutput()
require.NoError(t, err, fmt.Sprintf("执行 go generate 失败: %v\n%s", err, output))
}
cleanup操作,可选
dir: "./testdata/user_service2", | ||
svcName: "UserSvc", | ||
want: []string{"A", "B"}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
补充测试用例:
- svcName 为空
- svcName 非空但找不到
需要确认LoadService的语义:
dir下非空, ./testdata/user_service3下有 c和d, svcName 也非空, 就是没有与之匹配的,是报错还是返回nil, nil ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我直接把,plugin原生的报错吐出去了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以自定义一个err说明情况, 然后wrap plugin的err
spi/spi_test.go
Outdated
dir string | ||
svcName string | ||
want []string | ||
checkErr func(err error, t *testing.T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改为 assertFunc assert.ErrorAssertionFunc
使用
assertFunc: assert.NoError
assertFunc: assert.Error,
assertFunc: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.ErrorIs(t, err, DirNotFound)
},
dir: "./testdata/user_service2", | ||
svcName: "UserSvc", | ||
want: []string{"A", "B"}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以自定义一个err说明情况, 然后wrap plugin的err
这个测试需要依赖.so文件,直接用cmd命令行创建可行吗