Skip to content

Commit 01aaf11

Browse files
JohonsoyJames Cor
authored andcommitted
test: optimize database connection test logic
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
1 parent 50fd62f commit 01aaf11

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

_example/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestExampleRootUserEnabled(t *testing.T) {
6565
}()
6666
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
6767
require.NoError(t, err)
68-
require.ErrorContains(t, conn.Ping(), "User not found")
68+
require.ErrorContains(t, conn.Ping(), "No authentication methods available for authentication")
6969
conn, err = dbr.Open("mysql", fmt.Sprintf("root:@tcp(%s:%d)/%s", address, port, dbName), nil)
7070
require.NoError(t, err)
7171
require.NoError(t, conn.Ping())
@@ -86,10 +86,10 @@ func TestExampleLoadedUser(t *testing.T) {
8686
}()
8787
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
8888
require.NoError(t, err)
89-
require.ErrorContains(t, conn.Ping(), "User not found")
89+
require.ErrorContains(t, conn.Ping(), "No authentication methods available for authentication")
9090
conn, err = dbr.Open("mysql", fmt.Sprintf("root:@tcp(%s:%d)/%s", address, port, dbName), nil)
9191
require.NoError(t, err)
92-
require.ErrorContains(t, conn.Ping(), "User not found")
92+
require.ErrorContains(t, conn.Ping(), "No authentication methods available for authentication")
9393
conn, err = dbr.Open("mysql",
9494
fmt.Sprintf("gms_user:123456@tcp(%s:%d)/%s?allowCleartextPasswords=true", address, port, dbName), nil)
9595
require.NoError(t, err)

0 commit comments

Comments
 (0)