forked from ory/dockertest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockertest_test.go
More file actions
57 lines (50 loc) · 1.31 KB
/
dockertest_test.go
File metadata and controls
57 lines (50 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dockertest
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"log"
"os"
"testing"
)
var docker = os.Getenv("DOCKER_URL")
var pool *Pool
func TestMain(m *testing.M) {
var err error
pool, err = NewPool(docker)
if err != nil {
log.Fatalf("Could not connect to docker: %s", err)
}
os.Exit(m.Run())
}
func TestMySQL(t *testing.T) {
resource, err := pool.Run("mysql", "5.6", []string{"MYSQL_ROOT_PASSWORD=secret"})
require.Nil(t, err)
assert.NotEmpty(t, resource.GetPort("3306/tcp"))
err = pool.Retry(func() error {
db, err := sql.Open("mysql", fmt.Sprintf("root:secret@(localhost:%s)/mysql", resource.GetPort("3306/tcp")))
if err != nil {
return err
}
return db.Ping()
})
require.Nil(t, err)
require.Nil(t, pool.Purge(resource))
}
func TestPostgres(t *testing.T) {
resource, err := pool.Run("postgres", "9.5", nil)
require.Nil(t, err)
assert.NotEmpty(t, resource.GetPort("5432/tcp"))
err = pool.Retry(func() error {
db, err := sql.Open("postgres", fmt.Sprintf("postgres://postgres:secret@localhost:%s/postgres?sslmode=disable", resource.GetPort("5432/tcp")))
if err != nil {
return err
}
return db.Ping()
})
require.Nil(t, err)
require.Nil(t, pool.Purge(resource))
}