-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The wait.ForSQL wait strategy does not have a testcase and I forgot about how to use it as well. I decided to write it in preparation for the work/discussion ongoing here: #166
- Loading branch information
Gianluca Arbezzano
committed
Jun 16, 2020
1 parent
09610fb
commit 7623f53
Showing
2 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package wait_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/docker/go-connections/nat" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/wait" | ||
) | ||
|
||
func Test_ForSql(t *testing.T) { | ||
ctx := context.Background() | ||
req := testcontainers.GenericContainerRequest{ | ||
ContainerRequest: testcontainers.ContainerRequest{ | ||
Image: "mysql:8.0.20", | ||
ExposedPorts: []string{"3306/tcp"}, | ||
Env: map[string]string{ | ||
"MYSQL_ROOT_PASSWORD": "root", | ||
"MYSQL_DATABASE": "db", | ||
}, | ||
WaitingFor: wait.ForSQL("3306/tcp", "mysql", func(p nat.Port) string { | ||
return "root:root@tcp(localhost:" + p.Port() + ")/db" | ||
}), | ||
}, | ||
Started: true, | ||
} | ||
c, err := testcontainers.GenericContainer(ctx, req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer c.Terminate(ctx) | ||
} |