-
Notifications
You must be signed in to change notification settings - Fork 3
/
options_test.go
73 lines (55 loc) · 1.73 KB
/
options_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
package redisprom_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/globocom/go-redis-prometheus"
)
func TestOptions(t *testing.T) {
assert := assert.New(t)
t.Run("return default options", func(t *testing.T) {
assert.Equal(&redisprom.Options{
InstanceName: "unnamed",
Namespace: "",
DurationBuckets: []float64{.001, .005, .01, .025, .05, .1, .25, .5, 1},
}, redisprom.DefaultOptions())
})
t.Run("merge default options with custom values", func(t *testing.T) {
// arrange
custom1 := func(options *redisprom.Options) { options.InstanceName = "cache" }
custom2 := func(options *redisprom.Options) { options.Namespace = "custom" }
custom3 := func(options *redisprom.Options) { options.DurationBuckets = []float64{0.1} }
options := redisprom.DefaultOptions()
// act
options.Merge(custom1, custom2, custom3)
// assert
assert.Equal(&redisprom.Options{
InstanceName: "cache",
Namespace: "custom",
DurationBuckets: []float64{0.1},
}, options)
})
t.Run("customize the name of the Redis instance", func(t *testing.T) {
// arrange
options := redisprom.DefaultOptions()
// act
redisprom.WithInstanceName("cache")(options)
// assert
assert.Equal("cache", options.InstanceName)
})
t.Run("customize metrics namespace", func(t *testing.T) {
// arrange
options := redisprom.DefaultOptions()
// act
redisprom.WithNamespace("custom")(options)
// assert
assert.Equal("custom", options.Namespace)
})
t.Run("customize metrics duration buckets", func(t *testing.T) {
// arrange
options := redisprom.DefaultOptions()
// act
redisprom.WithDurationBuckets([]float64{0.01})(options)
// assert
assert.Equal([]float64{0.01}, options.DurationBuckets)
})
}