forked from steebchen/prisma-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresql.go
41 lines (29 loc) · 908 Bytes
/
postgresql.go
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
package postgresql
import (
"fmt"
"testing"
"github.com/bangbaew/prisma-client-go/test/cmd"
"github.com/bangbaew/prisma-client-go/test/setup"
)
const containerName = "go-client-postgres"
var PostgreSQL = &postgreSQL{}
type postgreSQL struct{}
func (*postgreSQL) Name() string {
return "postgresql"
}
func (*postgreSQL) ConnectionString(mockDBName string) string {
return fmt.Sprintf("postgresql://postgres:pw@localhost:5433/%s", mockDBName)
}
func (*postgreSQL) SetupDatabase(t *testing.T) string {
mockDB := setup.RandomString()
exec(t, fmt.Sprintf("CREATE DATABASE %s", mockDB))
return mockDB
}
func (*postgreSQL) TeardownDatabase(t *testing.T, mockDB string) {
exec(t, fmt.Sprintf("DROP DATABASE %s", mockDB))
}
func exec(t *testing.T, query string) {
if err := cmd.Run("docker", "exec", "-t", containerName, "psql", "-U", "postgres", "-c", query); err != nil {
t.Fatal(err)
}
}