Skip to content

Commit 2feaaad

Browse files
committed
Update dktest from v0.2.0 to v0.3.0
- Update ReadyFuncs accordingly
1 parent 9870a84 commit 2feaaad

File tree

11 files changed

+42
-23
lines changed

11 files changed

+42
-23
lines changed

Gopkg.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@
103103

104104
[[constraint]]
105105
name = "github.com/dhui/dktest"
106-
version = "0.2.2"
106+
version = "0.3.0"

database/cassandra/cassandra_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cassandra
22

33
import (
4+
"context"
45
"fmt"
56
"strconv"
67
"testing"
@@ -24,7 +25,7 @@ var (
2425
}
2526
)
2627

27-
func isReady(c dktest.ContainerInfo) bool {
28+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
2829
// Cassandra exposes 5 ports (7000, 7001, 7199, 9042 & 9160)
2930
// We only need the port bound to 9042
3031
ip, portStr, err := c.Port(9042)

database/cockroachdb/cockroachdb_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cockroachdb
33
// error codes https://github.com/lib/pq/blob/master/error.go
44

55
import (
6+
"context"
67
"database/sql"
78
"fmt"
89
"strings"
@@ -26,7 +27,7 @@ var (
2627
specs = []dktesting.ContainerSpec{{ImageName: "cockroachdb/cockroach:v1.0.2", Options: opts}}
2728
)
2829

29-
func isReady(c dktest.ContainerInfo) bool {
30+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
3031
ip, port, err := c.Port(defaultPort)
3132
if err != nil {
3233
fmt.Println("port error:", err)
@@ -38,7 +39,7 @@ func isReady(c dktest.ContainerInfo) bool {
3839
fmt.Println("open error:", err)
3940
return false
4041
}
41-
if err := db.Ping(); err != nil {
42+
if err := db.PingContext(ctx); err != nil {
4243
fmt.Println("ping error:", err)
4344
return false
4445
}

database/mongodb/mongodb_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ func mongoConnectionString(host, port string) string {
3636
return fmt.Sprintf("mongodb://%s:%s/testMigration?connect=single", host, port)
3737
}
3838

39-
func isReady(c dktest.ContainerInfo) bool {
39+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
4040
ip, port, err := c.FirstPort()
4141
if err != nil {
4242
return false
4343
}
4444

45-
client, err := mongo.Connect(context.TODO(), mongoConnectionString(ip, port))
45+
client, err := mongo.Connect(ctx, mongoConnectionString(ip, port))
4646
if err != nil {
4747
return false
4848
}
49-
defer client.Disconnect(context.TODO())
50-
if err = client.Ping(context.TODO(), nil); err != nil {
49+
defer client.Disconnect(ctx)
50+
if err = client.Ping(ctx, nil); err != nil {
5151
switch err {
5252
case io.EOF:
5353
return false

database/mysql/mysql_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mysql
22

33
import (
4+
"context"
45
"database/sql"
56
sqldriver "database/sql/driver"
67
"fmt"
@@ -33,7 +34,7 @@ var (
3334
}
3435
)
3536

36-
func isReady(c dktest.ContainerInfo) bool {
37+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
3738
ip, port, err := c.Port(defaultPort)
3839
if err != nil {
3940
return false
@@ -44,7 +45,7 @@ func isReady(c dktest.ContainerInfo) bool {
4445
return false
4546
}
4647
defer db.Close()
47-
if err = db.Ping(); err != nil {
48+
if err = db.PingContext(ctx); err != nil {
4849
switch err {
4950
case sqldriver.ErrBadConn, mysql.ErrInvalidConn:
5051
return false

database/postgres/postgres_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func pgConnectionString(host, port string) string {
3737
return fmt.Sprintf("postgres://postgres@%s:%s/postgres?sslmode=disable", host, port)
3838
}
3939

40-
func isReady(c dktest.ContainerInfo) bool {
40+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
4141
ip, port, err := c.FirstPort()
4242
if err != nil {
4343
return false
@@ -48,7 +48,7 @@ func isReady(c dktest.ContainerInfo) bool {
4848
return false
4949
}
5050
defer db.Close()
51-
if err = db.Ping(); err != nil {
51+
if err = db.PingContext(ctx); err != nil {
5252
switch err {
5353
case sqldriver.ErrBadConn, io.EOF:
5454
return false

database/redshift/redshift_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func connectionString(schema, host, port string) string {
4242
return fmt.Sprintf("%s://postgres@%s:%s/postgres?sslmode=disable", schema, host, port)
4343
}
4444

45-
func isReady(c dktest.ContainerInfo) bool {
45+
func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
4646
ip, port, err := c.FirstPort()
4747
if err != nil {
4848
return false
@@ -53,7 +53,7 @@ func isReady(c dktest.ContainerInfo) bool {
5353
return false
5454
}
5555
defer db.Close()
56-
if err = db.Ping(); err != nil {
56+
if err = db.PingContext(ctx); err != nil {
5757
switch err {
5858
case sqldriver.ErrBadConn, io.EOF:
5959
return false

dktesting/example_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dktesting_test
22

33
import (
4+
"context"
45
"testing"
56
)
67

@@ -15,9 +16,9 @@ import (
1516
func ExampleParallelTest() {
1617
t := &testing.T{} // Should actually be used in a Test
1718

18-
var isReady = func(c dktest.ContainerInfo) bool {
19+
var isReady = func(ctx context.Context, c dktest.ContainerInfo) bool {
1920
// Return true if the container is ready to run tests.
20-
// Don't block here though.
21+
// Don't block here though. Use the Context to timeout container ready checks.
2122
return true
2223
}
2324

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ require (
88
github.com/cockroachdb/apd v1.1.0 // indirect
99
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c
1010
github.com/cznic/ql v1.2.0
11-
github.com/dhui/dktest v0.2.2
11+
github.com/dhui/dktest v0.3.0
1212
github.com/docker/docker v0.7.3-0.20190108045446-77df18c24acf
1313
github.com/fsouza/fake-gcs-server v1.3.0
1414
github.com/go-ini/ini v1.39.0 // indirect
1515
github.com/go-sql-driver/mysql v1.4.1
1616
github.com/go-stack/stack v1.8.0 // indirect
1717
github.com/gocql/gocql v0.0.0-20181124151448-70385f88b28b
18+
github.com/golang/mock v1.2.0 // indirect
1819
github.com/google/go-github v17.0.0+incompatible
1920
github.com/google/go-querystring v1.0.0 // indirect
2021
github.com/google/martian v2.1.0+incompatible // indirect
@@ -39,14 +40,16 @@ require (
3940
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
4041
github.com/xdg/stringprep v1.0.0 // indirect
4142
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
42-
golang.org/x/net v0.0.0-20190107210223-45ffb0cd1ba0
43+
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
44+
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e
4345
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 // indirect
4446
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
4547
golang.org/x/sys v0.0.0-20190108104531-7fbe1cd0fcc2 // indirect
46-
golang.org/x/tools v0.0.0-20190107155254-e063def13b29
48+
golang.org/x/tools v0.0.0-20190108222858-421f03a57a64
4749
google.golang.org/api v0.0.0-20181015145326-625cd1887957
4850
google.golang.org/appengine v1.4.0 // indirect
49-
google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f
51+
google.golang.org/genproto v0.0.0-20190108161440-ae2f86662275
5052
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
5153
gopkg.in/ini.v1 v1.39.0 // indirect
54+
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a // indirect
5255
)

0 commit comments

Comments
 (0)