Skip to content
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

Merged
merged 14 commits into from
Jun 4, 2024
Merged

spi添加 #258

merged 14 commits into from
Jun 4, 2024

Conversation

juniaoshaonian
Copy link
Contributor

@juniaoshaonian juniaoshaonian commented May 23, 2024

这个测试需要依赖.so文件,直接用cmd命令行创建可行吗

@@ -0,0 +1,25 @@
// Copyright 2021 ecodeclub
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 既然user_service目录和user_service2目录只在测试中使用, 将其移动到/spi/testdata中, 研究一下go中testdata的用法.
  2. 选择使用go plugin方法实现,需要添加readme,或者Example来一步一步指导用户如何使用

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 按照 testdata 的用法修改
  2. 写一个简单的 Example 就可以

.github/pre-push Outdated Show resolved Hide resolved
.github/workflows/go.yml Outdated Show resolved Hide resolved
spi/spi_test.go Outdated
"github.com/stretchr/testify/assert"
)

func Test_LoadService(t *testing.T) {
Copy link
Collaborator

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"},
},
Copy link
Collaborator

@longyue0521 longyue0521 May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充测试用例:

  1. svcName 为空
  2. svcName 非空但找不到

需要确认LoadService的语义:

dir下非空, ./testdata/user_service3下有 c和d, svcName 也非空, 就是没有与之匹配的,是报错还是返回nil, nil ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我直接把,plugin原生的报错吐出去了

Copy link
Collaborator

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/testdata/user_service/a.go Show resolved Hide resolved
spi/testdata/user_service2/a/a.go Show resolved Hide resolved
spi/testdata/user_service2/b/b.go Show resolved Hide resolved
spi/testdata/user_service2/gen.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated
dir string
svcName string
want []string
checkErr func(err error, t *testing.T)
Copy link
Collaborator

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"},
},
Copy link
Collaborator

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.go Outdated Show resolved Hide resolved
spi/spi.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated Show resolved Hide resolved
@juniaoshaonian juniaoshaonian changed the title [WIP] spi添加 spi添加 Jun 3, 2024
spi/spi.go Outdated Show resolved Hide resolved
spi/spi.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated Show resolved Hide resolved
spi/spi_test.go Outdated Show resolved Hide resolved
spi/spi.go Outdated Show resolved Hide resolved
@longyue0521 longyue0521 merged commit 6fdf3ad into ecodeclub:dev Jun 4, 2024
4 checks passed
@longyue0521 longyue0521 mentioned this pull request Jun 4, 2024
bigdavidwong pushed a commit to bigdavidwong/ekit that referenced this pull request Nov 2, 2024
flycash pushed a commit that referenced this pull request Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants