forked from cloudfoundry-incubator/pat
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconn_test.go
75 lines (65 loc) · 1.73 KB
/
conn_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
72
73
74
75
package redis_test
import (
"os/exec"
"path/filepath"
"runtime"
"time"
. "github.com/cloudfoundry-incubator/pat/redis"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Conn", func() {
BeforeEach(func() {
StartRedis("redis.conf")
})
AfterEach(func() {
StopRedis()
})
Describe("Connecting", func() {
Context("When the host is wrong", func() {
It("Returns an error", func() {
_, err := Connect("fishfinger", 63798, "p4ssw0rd")
Ω(err).Should(HaveOccurred())
})
})
Context("When the port is wrong", func() {
It("Returns an error", func() {
_, err := Connect("localhost", 63799, "p4ssw0rd")
Ω(err).Should(HaveOccurred())
})
})
Context("When the host and port are correct", func() {
Context("But the password is wrong", func() {
It("Returns an error", func() {
_, err := Connect("localhost", 63799, "WRONG")
Ω(err).Should(HaveOccurred())
})
})
Context("And the password is correct", func() {
It("works", func() {
_, err := Connect("localhost", 63798, "p4ssw0rd")
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("When the server has no password", func() {
It("works", func() {
StopRedis()
StartRedis("redis.nopass.conf")
_, err := Connect("localhost", 63798, "")
Ω(err).ShouldNot(HaveOccurred())
})
})
})
})
})
func StartRedis(config string) {
_, filename, _, _ := runtime.Caller(0)
dir, _ := filepath.Abs(filepath.Dir(filename))
StopRedis()
exec.Command("redis-server", dir+"/"+config).Run()
time.Sleep(450 * time.Millisecond) // yuck(jz)
}
func StopRedis() {
exec.Command("redis-cli", "-p", "63798", "shutdown").Run()
exec.Command("redis-cli", "-p", "63798", "-a", "p4ssw0rd", "shutdown").Run()
}