-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathConfigSettingTest.groovy
More file actions
85 lines (73 loc) · 2.6 KB
/
ConfigSettingTest.groovy
File metadata and controls
85 lines (73 loc) · 2.6 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
82
83
84
85
package datadog.trace.api
import spock.lang.Specification
class ConfigSettingTest extends Specification {
def "supports equality check"() {
when:
def cs1 = ConfigSetting.of(key1, value1, origin1)
def cs2 = ConfigSetting.of(key2, value2, origin2)
then:
if (key1 == key2 && value1 == value2 && origin1 == origin2) {
assert cs1.hashCode() == cs2.hashCode()
assert cs1 == cs2
assert cs2 == cs1
assert cs1.toString() == cs2.toString()
} else {
assert cs1.hashCode() != cs2.hashCode()
assert cs1 != cs2
assert cs2 != cs1
assert cs1.toString() != cs2.toString()
}
where:
key1 | key2 | value1 | value2 | origin1 | origin2
"key" | "key" | "value" | "value" | ConfigOrigin.DEFAULT | ConfigOrigin.DEFAULT
"key" | "key2" | "value" | "value" | ConfigOrigin.ENV | ConfigOrigin.ENV
"key" | "key" | "value2" | "value" | ConfigOrigin.JVM_PROP | ConfigOrigin.JVM_PROP
"key" | "key" | "value" | "value" | ConfigOrigin.ENV | ConfigOrigin.DEFAULT
}
def "filters key values"() {
expect:
ConfigSetting.of(key, value, ConfigOrigin.DEFAULT).stringValue() == filteredValue
where:
key | value | filteredValue
"DD_API_KEY" | "somevalue" | "<hidden>"
"dd.api-key" | "somevalue" | "<hidden>"
"dd.profiling.api-key" | "somevalue" | "<hidden>"
"dd.profiling.apikey" | "somevalue" | "<hidden>"
"some.other.key" | "somevalue" | "somevalue"
}
def "support basic types"() {
expect:
ConfigSetting.of("key", value, ConfigOrigin.DEFAULT).stringValue() == rendered
where:
value | rendered
null | null
true | "true"
false | "false"
1 | "1"
1.0 | "1.0"
2.33f | "2.33"
"string" | "string"
}
def "convert Iterable, Map, and BitSet to String"() {
expect:
ConfigSetting.of("key", value, ConfigOrigin.DEFAULT).stringValue() == rendered
where:
value | rendered
["1", "2", "3"] | "1,2,3"
[1, 2, 3] | "1,2,3"
[1.0f, 22.23d, 3.1415] | "1.0,22.23,3.1415"
[a: 1, b: 2] | "a:1,b:2"
[a: "1", b: "2"] | "a:1,b:2"
[:] | ""
[] | ""
bitSetIntervals() | "33,200-300,303,400-500"
}
BitSet bitSetIntervals() {
def bitSetIntervals = new BitSet()
bitSetIntervals.set(33)
bitSetIntervals.set(200, 300)
bitSetIntervals.set(303)
bitSetIntervals.set(400, 500)
return bitSetIntervals
}
}