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

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

3DRX
Copy link
Contributor

@3DRX 3DRX commented Jul 16, 2024

using strings.Contains

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • 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
Copy link
Contributor Author

3DRX commented Jul 16, 2024

关于测试: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)
		}
	}

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

@Skyenought
Copy link
Contributor

你添加一个测试用例吧

@3DRX
Copy link
Contributor Author

3DRX commented Jul 17, 2024

你添加一个测试用例吧

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

Copy link
Contributor

@Skyenought Skyenought left a comment

Choose a reason for hiding this comment

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

lgtm

@Skyenought Skyenought requested a review from FGYFFFF July 19, 2024 11:32
@3DRX 3DRX requested a review from Skyenought July 26, 2024 09:11
@Skyenought
Copy link
Contributor

@FGYFFFF

@3DRX 3DRX requested a review from PazVz July 31, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

生成 model 文件路径不符合预期
3 participants