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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _example/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net"
"testing"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/gocraft/dbr/v2"
Expand All @@ -40,6 +41,8 @@ func TestExampleUsersDisabled(t *testing.T) {
main()
}()

// Wait for the database to start
time.Sleep(1 * time.Second)
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
require.NoError(t, err)
require.NoError(t, conn.Ping())
Expand All @@ -57,7 +60,6 @@ func TestExampleRootUserEnabled(t *testing.T) {
go func() {
main()
}()

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

Expand All @@ -78,7 +80,6 @@ func TestExampleLoadedUser(t *testing.T) {
go func() {
main()
}()

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")
Expand All @@ -103,7 +104,6 @@ func TestIssue1621(t *testing.T) {
go func() {
main()
}()

conn, err := dbr.Open("mysql",
fmt.Sprintf("root:@tcp(localhost:%d)/mydb", port), nil)
require.NoError(t, err)
Expand Down