hertz icon indicating copy to clipboard operation
hertz copied to clipboard

fix(cmd/hz): unexpected generated model file path

Open 3DRX opened this issue 1 year ago • 4 comments

using strings.Contains

What type of PR is this?

Check the PR title.

  • [x] This PR title match the format: <type>(optional scope): <description>
  • [x] The description of this PR title is user-oriented and clear enough for others to understand.
  • [x] Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

Translate the PR title into Chinese.

解决:生成 model 文件路径不符合预期

More detailed description for this PR(en: English/zh: Chinese).

en: Originally in Plugin.fixGoPackage, we used strings.Contains to decide if the go_package string already contains the top-level package name. Still, as #1154 shows, this can cause trouble when go_package happens to contain a substring that's identical to top level package name. zh: 原有的 Plugin.fixGoPackage 中使用 strings.Contains 来判断 go_package 中是否包含项目包名,但是如 #1154 ,这样会导致路径其他地方包含同样字串时路径错误。

Which issue(s) this PR fixes:

Fixes #1154

3DRX avatar Jul 16 '24 08:07 3DRX

关于测试:plugin_test.go 中 TestFixModelPathAndPackage 内有这段

	for _, r := range ret1 {
		tmp := r[0]
		if !strings.Contains(tmp, plu.Package) {
			if strings.HasPrefix(tmp, "/") {
				tmp = plu.Package + tmp
			} else {
				tmp = plu.Package + "/" + tmp
			}
		}
		result, _ := plu.fixModelPathAndPackage(tmp)
		if result != r[1] {
			t.Fatalf("want go package: %s, but get: %s", r[1], result)
		}
	}

是否应该更新这个测试用例,还是追加一个测试用例。

3DRX avatar Jul 16 '24 09:07 3DRX

你添加一个测试用例吧

Skyenought avatar Jul 16 '24 13:07 Skyenought

你添加一个测试用例吧

我提交了一个 commit 把一部分逻辑提到一个函数里使其更好测试,并添加了一组测试用例。

3DRX avatar Jul 17 '24 15:07 3DRX

@FGYFFFF

Skyenought avatar Jul 27 '24 08:07 Skyenought