forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_postgres.go
108 lines (93 loc) · 3.33 KB
/
test_postgres.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"path/filepath"
"strings"
ct "github.com/flynn/flynn/controller/types"
"github.com/flynn/flynn/discoverd/client"
"github.com/flynn/flynn/pkg/postgres"
c "github.com/flynn/go-check"
)
type PostgresSuite struct {
Helper
}
var _ = c.ConcurrentSuite(&PostgresSuite{})
// Check postgres config to avoid regressing on https://github.com/flynn/flynn/issues/101
func (s *PostgresSuite) TestSSLRenegotiationLimit(t *c.C) {
query := flynn(t, "/", "-a", "controller", "pg", "psql", "--", "-c", "SHOW ssl_renegotiation_limit")
t.Assert(query, SuccessfulOutputContains, "ssl_renegotiation_limit \n-------------------------\n 0\n(1 row)")
}
func (s *PostgresSuite) TestDumpRestore(t *c.C) {
r := s.newGitRepo(t, "empty")
t.Assert(r.flynn("create"), Succeeds)
res := r.flynn("resource", "add", "postgres")
t.Assert(res, Succeeds)
id := strings.Split(res.Output, " ")[2]
t.Assert(r.flynn("pg", "psql", "--", "-c",
"CREATE table foos (data text); INSERT INTO foos (data) VALUES ('foobar')"), Succeeds)
file := filepath.Join(t.MkDir(), "db.dump")
t.Assert(r.flynn("pg", "dump", "-f", file), Succeeds)
t.Assert(r.flynn("pg", "psql", "--", "-c", "DROP TABLE foos"), Succeeds)
r.flynn("pg", "restore", "-f", file)
query := r.flynn("pg", "psql", "--", "-c", "SELECT * FROM foos")
t.Assert(query, SuccessfulOutputContains, "foobar")
t.Assert(r.flynn("resource", "remove", "postgres", id), Succeeds)
}
var sireniaPostgres = sireniaDatabase{
appName: "postgres",
serviceKey: "FLYNN_POSTGRES",
hostKey: "PGHOST",
initDb: func(t *c.C, r *ct.Release, d *sireniaDeploy) {
db := postgres.Wait(&postgres.Conf{
Discoverd: discoverd.NewClientWithURL(fmt.Sprintf("http://%s:1111", routerIP)),
Service: d.name,
User: "flynn",
Password: r.Env["PGPASSWORD"],
Database: "postgres",
}, nil)
dbname := "deploy-test"
t.Assert(db.Exec(fmt.Sprintf(`CREATE DATABASE "%s" WITH OWNER = "flynn"`, dbname)), c.IsNil)
db.Close()
db = postgres.Wait(&postgres.Conf{
Discoverd: discoverd.NewClientWithURL(fmt.Sprintf("http://%s:1111", routerIP)),
Service: d.name,
User: "flynn",
Password: r.Env["PGPASSWORD"],
Database: dbname,
}, nil)
defer db.Close()
t.Assert(db.Exec(`CREATE TABLE deploy_test ( data text)`), c.IsNil)
},
assertWriteable: func(t *c.C, r *ct.Release, d *sireniaDeploy) {
dbname := "deploy-test"
db := postgres.Wait(&postgres.Conf{
Discoverd: discoverd.NewClientWithURL(fmt.Sprintf("http://%s:1111", routerIP)),
Service: d.name,
User: "flynn",
Password: r.Env["PGPASSWORD"],
Database: dbname,
}, nil)
defer db.Close()
debug(t, "writing to postgres database")
t.Assert(db.ExecRetry(`INSERT INTO deploy_test (data) VALUES ('data')`), c.IsNil)
},
}
// Sirenia integration tests
func (s *PostgresSuite) TestDeploySingleAsync(t *c.C) {
testSireniaDeploy(s.controllerClient(t), s.discoverdClient(t), t, &sireniaDeploy{
name: "postgres-single-async",
db: sireniaPostgres,
sireniaJobs: 3,
webJobs: 2,
expected: testDeploySingleAsync,
})
}
func (s *PostgresSuite) TestDeployMultipleAsync(t *c.C) {
testSireniaDeploy(s.controllerClient(t), s.discoverdClient(t), t, &sireniaDeploy{
name: "postgres-multiple-async",
db: sireniaPostgres,
sireniaJobs: 5,
webJobs: 2,
expected: testDeployMultipleAsync,
})
}