-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer_test.go
More file actions
38 lines (33 loc) · 968 Bytes
/
container_test.go
File metadata and controls
38 lines (33 loc) · 968 Bytes
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
package testcontainerpostgres_test
import (
"context"
"path/filepath"
"regexp"
"testing"
"github.com/thlib/testcontainerpostgres"
)
// TestNew runs an example postgresql container
func TestNew(t *testing.T) {
schemaPath, err := filepath.Abs("./initdb")
if err != nil {
t.Fatalf("%v", err)
}
ctx := context.Background()
postgresC, conn, err := testcontainerpostgres.New(ctx, "14.5-alpine",
testcontainerpostgres.WithInit(schemaPath),
testcontainerpostgres.WithDb("test_db"),
testcontainerpostgres.WithAuth("postgres", "postgres"),
)
if err != nil {
t.Fatalf("%v", err)
}
defer testcontainerpostgres.Terminate(ctx, postgresC)
expected := regexp.QuoteMeta("postgres://postgres:postgres@localhost:") + "[0-9]+" + regexp.QuoteMeta("/test_db")
rx, err := regexp.Compile(expected)
if err != nil {
t.Fatalf("%v", err)
}
if !rx.MatchString(conn) {
t.Errorf("Expected a connection string that looks like: %v, got: %v", expected, conn)
}
}