MCPcopy
hub / github.com/perkeep/perkeep / SetupPostgreSQLContainer

Function SetupPostgreSQLContainer

pkg/test/dockertest/docker.go:325–344  ·  view source on GitHub ↗

SetupPostgreSQLContainer sets up a real PostgreSQL instance for testing purposes, using a Docker container. It returns the container ID and its IP address, or makes the test fail on error. Currently using https://index.docker.io/u/nornagon/postgres

(t *testing.T, dbname string)

Source from the content-addressed store, hash-verified

323// or makes the test fail on error.
324// Currently using https://index.docker.io/u/nornagon/postgres
325func SetupPostgreSQLContainer(t *testing.T, dbname string) (c ContainerID, ip string) {
326 c, ip = setupContainer(t, postgresImage, 5432, 15*time.Second, func() (string, error) {
327 return run("-d", postgresImage)
328 })
329 cleanupAndDie := func(err error) {
330 c.KillRemove(t)
331 t.Fatal(err)
332 }
333 rootdb, err := sql.Open("postgres",
334 fmt.Sprintf("user=%s password=%s host=%s dbname=postgres sslmode=disable", PostgresUsername, PostgresPassword, ip))
335 if err != nil {
336 cleanupAndDie(fmt.Errorf("Could not open postgres rootdb: %v", err))
337 }
338 if _, err := sqlExecRetry(rootdb,
339 "CREATE DATABASE "+dbname+" LC_COLLATE = 'C' TEMPLATE = template0",
340 50); err != nil {
341 cleanupAndDie(fmt.Errorf("Could not create database %v: %v", dbname, err))
342 }
343 return
344}
345
346// sqlExecRetry keeps calling http://golang.org/pkg/database/sql/#DB.Exec on db
347// with stmt until it succeeds or until it has been tried maxTry times.

Callers 2

TestPostgreSQLKVFunction · 0.92
newPostgresSortedFunction · 0.92

Calls 6

setupContainerFunction · 0.85
sqlExecRetryFunction · 0.85
KillRemoveMethod · 0.80
FatalMethod · 0.80
runFunction · 0.70
OpenMethod · 0.65

Tested by 2

TestPostgreSQLKVFunction · 0.74
newPostgresSortedFunction · 0.74