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

Add host for sql waiter URL function. #166

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert this? it should be placed in your global gitignore

debug.test
vendor
14 changes: 10 additions & 4 deletions wait/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"time"
)

type URL func(string, nat.Port) string

//ForSQL constructs a new waitForSql strategy for the given driver
func ForSQL(port nat.Port, driver string, url func(nat.Port) string) *waitForSql {
func ForSQL(port nat.Port, driver string, url URL) *waitForSql {
return &waitForSql{
Port: port,
URL: url,
Expand All @@ -18,7 +20,7 @@ func ForSQL(port nat.Port, driver string, url func(nat.Port) string) *waitForSql
}

type waitForSql struct {
URL func(port nat.Port) string
URL URL
Driver string
Port nat.Port
startupTimeout time.Duration
Expand Down Expand Up @@ -47,7 +49,12 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)
return fmt.Errorf("target.MappedPort: %v", err)
}

db, err := sql.Open(w.Driver, w.URL(port))
host, err := target.Host(ctx)
if err != nil {
return fmt.Errorf("target.Host: %v", err)
}

db, err := sql.Open(w.Driver, w.URL(host, port))
if err != nil {
return fmt.Errorf("sql.Open: %v", err)
}
Expand All @@ -56,7 +63,6 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:

if _, err := db.ExecContext(ctx, "SELECT 1"); err != nil {
continue
}
Expand Down