Skip to content
Open
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
2 changes: 1 addition & 1 deletion database/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

import (
"github.com/dhui/dktest"
"github.com/gocql/gocql"
"github.com/golang-migrate/migrate/v4/dktest"
)

import (
Expand Down
2 changes: 1 addition & 1 deletion database/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"testing"

_ "github.com/ClickHouse/clickhouse-go"
"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/clickhouse"
dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktest"
"github.com/golang-migrate/migrate/v4/dktesting"
_ "github.com/golang-migrate/migrate/v4/source/file"
)
Expand Down
2 changes: 1 addition & 1 deletion database/cockroachdb/cockroachdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

import (
"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"
_ "github.com/lib/pq"
)

Expand Down
2 changes: 1 addition & 1 deletion database/firebird/firebird_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"testing"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"

dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktesting"
Expand Down
2 changes: 1 addition & 1 deletion database/mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

import (
"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down
2 changes: 1 addition & 1 deletion database/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"strconv"
"testing"

"github.com/dhui/dktest"
"github.com/go-sql-driver/mysql"
"github.com/golang-migrate/migrate/v4"
dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktest"
"github.com/golang-migrate/migrate/v4/dktesting"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion database/neo4j/neo4j_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"testing"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"
"github.com/neo4j/neo4j-go-driver/neo4j"

"github.com/golang-migrate/migrate/v4"
Expand Down
2 changes: 1 addition & 1 deletion database/pgx/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"sync"
"testing"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/dktest"

dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktesting"
Expand Down
2 changes: 1 addition & 1 deletion database/pgx/v5/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/golang-migrate/migrate/v4"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"

"github.com/golang-migrate/migrate/v4/database"
dt "github.com/golang-migrate/migrate/v4/database/testing"
Expand Down
2 changes: 1 addition & 1 deletion database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/golang-migrate/migrate/v4"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"

"github.com/golang-migrate/migrate/v4/database"
dt "github.com/golang-migrate/migrate/v4/database/testing"
Expand Down
2 changes: 1 addition & 1 deletion database/redshift/redshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

import (
"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"
)

import (
Expand Down
2 changes: 1 addition & 1 deletion database/rqlite/rqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"testing"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4/dktest"
"github.com/rqlite/gorqlite"
"github.com/stretchr/testify/assert"

Expand Down
2 changes: 1 addition & 1 deletion database/sqlserver/sqlserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/dktest"

dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktesting"
Expand Down
2 changes: 1 addition & 1 deletion database/yugabytedb/yugabytedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

"github.com/dhui/dktest"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/dktest"

_ "github.com/lib/pq"

Expand Down
96 changes: 96 additions & 0 deletions dktest/container_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package dktest

import (
"fmt"
"strconv"

"github.com/docker/go-connections/nat"
)

// ContainerInfo holds information about a running Docker container.
type ContainerInfo struct {
ID string
Name string
ImageName string
Ports nat.PortMap
}

func (c ContainerInfo) String() string {
return fmt.Sprintf("dktest.ContainerInfo{ID:%q, Name:%q, ImageName:%q}", c.ID, c.Name, c.ImageName)
}

// Port gets the specified published TCP port.
func (c ContainerInfo) Port(containerPort uint16) (hostIP string, hostPort string, err error) {
port, err := nat.NewPort("tcp", strconv.Itoa(int(containerPort)))
if err != nil {
return "", "", err
}
return mapPort(c.Ports, port)
}

// UDPPort gets the specified published UDP port.
func (c ContainerInfo) UDPPort(containerPort uint16) (hostIP string, hostPort string, err error) {
port, err := nat.NewPort("udp", strconv.Itoa(int(containerPort)))
if err != nil {
return "", "", err
}
return mapPort(c.Ports, port)
}

// FirstPort gets the first published TCP port.
func (c ContainerInfo) FirstPort() (hostIP string, hostPort string, err error) {
return firstPort(c.Ports, "tcp")
}

// FirstUDPPort gets the first published UDP port.
func (c ContainerInfo) FirstUDPPort() (hostIP string, hostPort string, err error) {
return firstPort(c.Ports, "udp")
}

func mapPort(portMap nat.PortMap, port nat.Port) (hostIP string, hostPort string, err error) {
if bindings, ok := portMap[port]; ok {
for _, binding := range bindings {
return mapHost(binding.HostIP), binding.HostPort, nil
}
}

portInt := port.Int()
proto := port.Proto()
for p, bindings := range portMap {
if p.Proto() != proto {
continue
}
start, end, err := p.Range()
if err != nil || portInt < start || portInt > end {
continue
}
offset := portInt - start
if offset >= len(bindings) {
continue
}
binding := bindings[offset]
return mapHost(binding.HostIP), binding.HostPort, nil
}
return "", "", errNoPort
}

func firstPort(portMap nat.PortMap, proto string) (hostIP string, hostPort string, err error) {
for port, bindings := range portMap {
if port.Proto() != proto {
continue
}
for _, binding := range bindings {
return mapHost(binding.HostIP), binding.HostPort, nil
}
}
return "", "", errNoPort
}

func mapHost(host string) string {
switch host {
case "", "0.0.0.0":
return "127.0.0.1"
default:
return host
}
}
Loading
Loading