forked from keighl/barkup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres_test.go
71 lines (57 loc) · 1.55 KB
/
postgres_test.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
package barkup
import (
"strings"
"testing"
)
func Test_Postgres_Export_Pass(t *testing.T) {
p := Postgres{
Host: "localhost",
Port: "5432",
DB: "test",
Username: "postgres",
}
PGDumpCmd = "true"
result := p.Export()
expect(t, result.Error, (*Error)(nil))
}
func Test_Postgres_Export_FailDump(t *testing.T) {
p := Postgres{
Host: "localhost",
Port: "5432",
DB: "test",
Username: "postgres",
}
PGDumpCmd = "false"
result := p.Export()
refute(t, result.Error, (*Error)(nil))
}
func Test_Postgres_optionsDump(t *testing.T) {
p := Postgres{
Host: "localhost",
Port: "5432",
DB: "test",
Username: "postgres",
Options: []string{"-W"},
}
options := strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-d"), true)
expect(t, strings.Contains(options, "-h"), true)
expect(t, strings.Contains(options, "-p"), true)
expect(t, strings.Contains(options, "-U"), true)
expect(t, strings.Contains(options, "-W"), true)
p.Host = ""
options = strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-h"), false)
p.Port = ""
options = strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-p"), false)
p.DB = ""
options = strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-d"), false)
p.Username = ""
options = strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-U"), false)
p.Options = []string{}
options = strings.Join(p.dumpOptions(), " ")
expect(t, strings.Contains(options, "-W"), false)
}