-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_test.go
More file actions
81 lines (68 loc) · 2.26 KB
/
config_test.go
File metadata and controls
81 lines (68 loc) · 2.26 KB
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
package steadyrabbit_test
import (
"github.com/BackAged/steadyrabbit"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/streadway/amqp"
)
func formPublisherConfig() *steadyrabbit.Config {
return &steadyrabbit.Config{
URL: "amqp://localhost",
}
}
var _ = Describe("Config", func() {
var (
cnf *steadyrabbit.Config
)
Describe("ValidatePublisherConfig", func() {
Context("validation combination of config", func() {
BeforeEach(func() {
cnf = formPublisherConfig()
})
It("errors with nil options", func() {
err := steadyrabbit.ValidatePublisherConfig(nil)
Expect(err).To(HaveOccurred())
})
It("errors when URL is empty", func() {
cnf.URL = ""
err := steadyrabbit.ValidatePublisherConfig(cnf)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("URL can not be empty"))
})
It("only requires ExchangeType, ExchangeName Exchange Declare is true", func() {
cnf.Publisher = &steadyrabbit.PublisherConfig{
Exchange: &steadyrabbit.ExchangeConfig{
ExchangeDeclare: true,
},
}
err := steadyrabbit.ValidatePublisherConfig(cnf)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("ExchangeType can not be empty if ExchangeDeclare set to true"))
cnf.Publisher = &steadyrabbit.PublisherConfig{
Exchange: &steadyrabbit.ExchangeConfig{
ExchangeDeclare: true,
ExchangeType: amqp.ExchangeDirect,
},
}
err = steadyrabbit.ValidatePublisherConfig(cnf)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("ExchangeName can not be empty if ExchangeDeclare set to true"))
cnf.Publisher = &steadyrabbit.PublisherConfig{
Exchange: &steadyrabbit.ExchangeConfig{
ExchangeDeclare: false,
},
}
err = steadyrabbit.ValidatePublisherConfig(cnf)
Expect(err).ToNot(HaveOccurred())
})
It("sets RetryConnectIntervalSec, AppID to default if unset", func() {
cnf.RetryReconnectIntervalSec = 0
cnf.AppID = ""
err := steadyrabbit.ValidatePublisherConfig(cnf)
Expect(err).ToNot(HaveOccurred())
Expect(cnf.RetryReconnectIntervalSec).To(Equal(steadyrabbit.DefaultRetryReconnectIntervalSec))
Expect(cnf.AppID).To(Equal(steadyrabbit.DefaultAppID))
})
})
})
})