-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
82 lines (64 loc) · 1.78 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
package graphite
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"time"
)
var _ = Describe("configuration", func() {
var (
config Config
)
Context("metrics path", func() {
var (
testPrefix = "alpha.instance"
)
BeforeEach(func() {
config = Config{
Namespace: testPrefix,
}
})
It("appends the prefix if set in the configuration", func() {
metricPath := "additional-path"
Expect(config.getMetricPath(metricPath)).To(Equal(testPrefix + "." + metricPath))
})
It("uses the prefix directly if no metric name is passed", func() {
Expect(config.getMetricPath("")).To(Equal(testPrefix))
})
It("uses the metric name directly if no prefix is configured", func() {
metricPath := "metric.path.count"
config.Namespace = ""
Expect(config.getMetricPath(metricPath)).To(Equal(metricPath))
})
})
Context("graphite address", func() {
BeforeEach(func() {
config = Config{
Host: "example.com",
Port: 2003,
}
})
It("constructs properly the endpoint string given a host and a port", func() {
Expect(config.getAddress()).To(Equal("example.com:2003"))
})
It("doesn't trigger an error if host is not set", func() {
config.Host = ""
Expect(config.getAddress()).To(Equal(":2003"))
})
It("doesn't trigger an error if port is not set", func() {
config.Port = 0
Expect(config.getAddress()).To(Equal("example.com:0"))
})
})
Context("client timeout", func() {
BeforeEach(func() {
config = Config{}
})
It("returns a default timeout of one seconds if none is provided", func() {
Expect(config.getTimeout()).To(Equal(1 * time.Second))
})
It("returns the timeout set as time duration", func() {
config.Timeout = 5 * time.Minute
Expect(config.getTimeout()).To(Equal(config.Timeout))
})
})
})