Skip to content

test: optimize database connection test logic #2991

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Johonsoy
Copy link
Contributor

  • Add a 1-second wait time before each test to ensure the database has started

  • Update error assertions to match more specific error messages

  • Adjust the test order: first test the case where the user does not exist, then test the case where the password is incorrect

Add a 1-second wait time before each test to ensure the database has started
Update error assertions to match more specific error messages
Adjust the test order: first test the case where the user does not exist, then test the case where the password is incorrect
Johonsoy added 3 commits May 24, 2025 00:16
Adjust code import order

- Adjust the import order of "github.com/gocraft/dbr/v2" to before "github.com/stretchr/testify/assert"
- This change does not add or remove any functionality, it just reorganizes the order of import statements
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

The sleep seems fine, but the assertions you removed were actually testing things.

conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
require.NoError(t, err)
require.ErrorContains(t, conn.Ping(), "User not found")
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure we want to keep these around

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted it,pls check again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants