-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 测试环境使用固定验证码 #427
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
feat: 测试环境使用固定验证码 #427
Conversation
Summary of ChangesHello @JavaPythonAIForBAT, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在通过在测试环境中提供一个固定的验证码"123456"来优化AI自动化测试流程。这消除了AI在测试时需要动态识别和输入随机验证码的复杂性,从而提高了测试的效率和稳定性。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
本次变更通过引入一个 IsTestEnvironment 配置项,实现了在测试环境中使用固定的验证码“123456”。整体实现思路清晰,通过 randomcode.RandomCode 接口区分了测试和生产环境的验证码生成逻辑,并添加了相应的单元测试,做得很好。
我发现一些可以改进的地方,主要是在新添加的代码中,固定的验证码“123456”在多个地方被硬编码。建议将其定义为一个公共常量,以提高代码的可维护性和一致性。具体的修改建议请见我的评论。
| func (t *TestRandomCode) New() (string, error) { | ||
| return "123456", nil | ||
| } | ||
|
|
||
| func (t *TestRandomCode) IsValid(code string) bool { | ||
| return code == "123456" | ||
| } |
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.
硬编码的字符串 "123456" 在 New 和 IsValid 方法中都有使用。建议将其定义为一个导出的常量(例如 TestVerificationCode),以提高代码的可维护性并避免“魔术字符串”,同时也能让其他包的测试代码复用这个常量。
例如,在文件顶部添加:
const TestVerificationCode = "123456"然后在这两个方法中使用这个常量。
| func (t *TestRandomCode) New() (string, error) { | |
| return "123456", nil | |
| } | |
| func (t *TestRandomCode) IsValid(code string) bool { | |
| return code == "123456" | |
| } | |
| func (t *TestRandomCode) New() (string, error) { | |
| return TestVerificationCode, nil | |
| } | |
| func (t *TestRandomCode) IsValid(code string) bool { | |
| return code == TestVerificationCode | |
| } |
| if code != "123456" { | ||
| t.Errorf("Expected '123456', got '%s'", code) | ||
| } |
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.
| if !testCode.IsValid("123456") { | ||
| t.Error("Expected '123456' to be valid") | ||
| } |
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.
| if code != "123456" { | ||
| t.Errorf("Expected '123456', got '%s'", code) | ||
| } |
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.
| } | ||
|
|
||
| // 测试验证码验证 | ||
| key := domain.NewVerificationCodeKey("123456", purpose) |
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.
| if code != "123456" { | ||
| t.Errorf("Expected '123456', got '%s'", code) | ||
| } |
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.
| } | ||
|
|
||
| func (t *TestRandomCode) IsValid(code string) bool { | ||
| return code == "123456" |
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.
这个最好弄个不这样容易被猜到的验证码放在配置文件里
6f9912a to
51b1f6f
Compare
|
测试环境如果所有邮件验证码发送同一个,会导致实际操作和生产环境不一样,需要指定某一个测试邮箱 |
AI自动化测试需要填写验证码,我们这里专门为测试环境生成固定的验证码“123456”