-
Notifications
You must be signed in to change notification settings - Fork 8
/
config_test.go
118 lines (93 loc) · 2.76 KB
/
config_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
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
109
110
111
112
113
114
115
116
117
118
package main_test
import (
"fmt"
"os"
. "github.com/BTBurke/twilio-voice"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Config", func() {
var cfg *Config
BeforeEach(func() {
cfg = &Config{
MailgunPublicKey: "abc123",
MailgunSecretKey: "pancakes",
MailgunDomain: "example.com",
ForwardingNumber: "+15555555",
NotificationEmail: "[email protected]",
}
})
Describe(".Validate", func() {
It("returns empty slice when valid", func() {
Expect(cfg.Validate()).To(BeEmpty())
})
whenVoicemailFile := func(desc, file string) {
Context(fmt.Sprintf(`when VoicemailFile is "%s"`, desc), func() {
JustBeforeEach(func() {
cfg.VoicemailFile = file
})
It("sets default VoicemailScript", func() {
cfg.VoicemailScript = ""
Expect(cfg.Validate()).To(BeEmpty())
Expect(cfg.VoicemailScript).To(Equal("Please leave a message"))
})
It("does not override custom VoicemailScript", func() {
cfg.VoicemailScript = "What do you want?!"
Expect(cfg.Validate()).To(BeEmpty())
Expect(cfg.VoicemailScript).To(Equal("What do you want?!"))
})
})
}
whenVoicemailFile("non-existent", "/path/to/a/nonexistent/file.mp3")
whenVoicemailFile("directory", "templates")
whenVoicemailFile("unspecified", "")
It("uses specified VoicemailFile when exists", func() {
wd, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())
cfg.VoicemailFile = "README.md"
Expect(cfg.Validate()).To(BeEmpty())
Expect(cfg.ServeDirectory).To(Equal(wd + "/"))
Expect(cfg.VoiceFileName).To(Equal("README.md"))
})
It("returns error when missing MailgunPublicKey", func() {
cfg.MailgunPublicKey = ""
errs := cfg.Validate()
Expect(len(errs)).To(Equal(1))
Expect(errs[0]).To(MatchError(
MatchRegexp("set.*MAILGUN_PUBLIC_KEY"),
))
})
It("returns error when missing MailgunSecretKey", func() {
cfg.MailgunSecretKey = ""
errs := cfg.Validate()
Expect(len(errs)).To(Equal(1))
Expect(errs[0]).To(MatchError(
MatchRegexp("set.*MAILGUN_SECRET_KEY"),
))
})
It("returns error when missing MailgunDomain", func() {
cfg.MailgunDomain = ""
errs := cfg.Validate()
Expect(len(errs)).To(Equal(1))
Expect(errs[0]).To(MatchError(
MatchRegexp("set.*MAILGUN_DOMAIN"),
))
})
It("returns error when missing NotificationEmail", func() {
cfg.NotificationEmail = ""
errs := cfg.Validate()
Expect(len(errs)).To(Equal(1))
Expect(errs[0]).To(MatchError(
MatchRegexp("set.*NOTIFICATION_EMAIL"),
))
})
It("returns error when missing ForwardingNumber", func() {
cfg.ForwardingNumber = ""
errs := cfg.Validate()
Expect(len(errs)).To(Equal(1))
Expect(errs[0]).To(MatchError(
MatchRegexp("set.*FORWARDING_NUMBER"),
))
})
})
})