-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathConfigConverterTest.groovy
More file actions
166 lines (147 loc) · 8.12 KB
/
Copy pathConfigConverterTest.groovy
File metadata and controls
166 lines (147 loc) · 8.12 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package datadog.trace.bootstrap.config.provider
import datadog.trace.test.util.DDSpecification
class ConfigConverterTest extends DDSpecification {
def "Convert boolean properties"() {
when:
def value = ConfigConverter.valueOf(stringValue, Boolean)
then:
value == expectedConvertedValue
where:
stringValue | expectedConvertedValue
"true" | true
"TRUE" | true
"True" | true
"1" | true
"false" | false
null | null
"" | null
"0" | false
}
def "parse map properly for #mapString"() {
when:
def result = ConfigConverter.parseMap(mapString, "test")
then:
result == expected
where:
// spotless:off
mapString | expected
"a:1, a:2, a:3" | [a: "3"]
"a:b,c:d,e:" | [a: "b", c: "d"]
// space separated
"a:1 a:2 a:3" | [a: "3"]
"a:b c:d e:" | [a: "b", c: "d"]
// More different string variants:
"a:a;" | [a: "a;"]
"a:1, a:2, a:3" | [a: "3"]
"a:1 a:2 a:3" | [a: "3"]
"a:b,c:d,e:" | [a: "b", c: "d"]
"a:b c:d e:" | [a: "b", c: "d"]
"key 1!:va|ue_1," | ["key 1!": "va|ue_1"]
"key 1!:va|ue_1 " | ["key 1!": "va|ue_1"]
" key1 :value1 ,\t key2: value2" | [key1: "value1", key2: "value2"]
'a:b, b:c, c:d, d: e' | ['a': 'b', 'b': 'c', 'c': 'd', 'd': 'e']
"key1 :value1 \t key2: value2" | [key1: "value1", key2: "value2"]
"dyno:web.1 dynotype:web appname:******" | ["dyno": "web.1", "dynotype": "web", "appname": "******"]
"is:val:id" | [is: "val:id"]
"a:b,is:val:id,x:y" | [a: "b", is: "val:id", x: "y"]
"a:b:c:d" | [a: "b:c:d"]
'fooa:barb, foob:barc, fooc: bard, food: bare,' | ['fooa': 'barb', 'foob': 'barc', 'fooc': 'bard', 'food': 'bare']
"a:b=c=d" | [a: "b=c=d"]
// Illegal
"a:" | [:]
"a:b,c,d" | [:]
"a:b,c,d,k:v" | [:]
"" | [:]
"1" | [:]
"a" | [:]
"a,1" | [:]
"!a" | [:]
" " | [:]
",,,," | [:]
":,:,:,:," | [:]
": : : : " | [:]
"::::" | [:]
'key1:val1 with_space:and_colon, key2:val2' | [:]
// spotless:on
}
def "parse map for #mapString with separator #separator"() {
when:
def result = ConfigConverter.parseMap(mapString, "test", separator as char)
then:
result == expected
where:
// spotless:off
mapString | separator | expected
"a=1, a=2, a=3" | '=' | [a: "3"]
"a=b,c=d,e=" | '=' | [a: "b", c: "d"]
"a;b,c;d,e;" | ';' | [a: "b", c: "d"]
// space separated
"a=1 a=2 a=3" | '=' | [a: "3"]
"a=b c=d e=" | '=' | [a: "b", c: "d"]
// More different string variants
"a=b=c=d" | '=' | [a: "b=c=d"]
'fooa=barb, foob=barc, fooc= bard, food= bare,' | '=' | ['fooa': 'barb', 'foob': 'barc', 'fooc': 'bard', 'food': 'bare']
"a=b:c:d" | '=' | [a: "b:c:d"]
// Illegal
"a=" | '=' | [:]
"====" | '=' | [:]
// spotless:on
}
def "parsing map #mapString with List of arg separators for with key value separator #separator"() {
//testing parsing for DD_TAGS
setup:
def separatorList = [',' as char, ' ' as char]
when:
def result = ConfigConverter.parseTraceTagsMap(mapString, separator as char, separatorList as List<Character>)
then:
result == expected
where:
// spotless:off
mapString | separator | expected
"key1:value1,key2:value2" | ':' | [key1: "value1", key2: "value2"]
"key1:value1 key2:value2" | ':' | [key1: "value1", key2: "value2"]
"env:test aKey:aVal bKey:bVal cKey:" | ':' | [env: "test", aKey: "aVal", bKey: "bVal", cKey:""]
"env:test,aKey:aVal,bKey:bVal,cKey:" | ':' | [env: "test", aKey: "aVal", bKey: "bVal", cKey:""]
"env:test,aKey:aVal bKey:bVal cKey:" | ':' | [env: "test", aKey: "aVal bKey:bVal cKey:"]
"env:test bKey :bVal dKey: dVal cKey:" | ':' | [env: "test", bKey: "", dKey: "", dVal: "", cKey: ""]
'env :test, aKey : aVal bKey:bVal cKey:' | ':' | [env: "test", aKey : "aVal bKey:bVal cKey:"]
"env:keyWithA:Semicolon bKey:bVal cKey" | ':' | [env: "keyWithA:Semicolon", bKey: "bVal", cKey: ""]
"env:keyWith: , , Lots:Of:Semicolons " | ':' | [env: "keyWith:", Lots: "Of:Semicolons"]
"a:b,c,d" | ':' | [a: "b", c: "", d: ""]
"a,1" | ':' | [a: "", "1": ""]
"a:b:c:d" | ':' | [a: "b:c:d"]
//edge cases
"noDelimiters" | ':' | [noDelimiters: ""]
" " | ':' | [:]
",,,,,,,,,,,," | ':' | [:]
", , , , , , " | ':' | [:]
// spotless:on
}
def "test parseMapWithOptionalMappings"() {
when:
def result = ConfigConverter.parseMapWithOptionalMappings(mapString, "test", "", lowercaseKeys)
then:
result == expected
where:
mapString | expected | lowercaseKeys
"header1:one,header2:two" | [header1: "one", header2: "two"] | false
"header1:one, header2:two" | [header1: "one", header2: "two"] | false
"header1,header2:two" | [header1: "header1", header2: "two"] | false
"Header1:one,header2:two" | [header1: "one", header2: "two"] | true
"\"header1:one,header2:two\"" | ["\"header1": "one", header2: "two\""] | true
"header1" | [header1: "header1"] | true
",header1:tag" | [header1: "tag"] | true
"header1:tag," | [header1: "tag"] | true
"header:tag:value" | [header: "tag:value"] | true
"" | [:] | true
null | [:] | true
// logs warning: Illegal key only tag starting with non letter '1header'
"1header,header2:two" | [:] | true
// logs warning: Illegal tag starting with non letter for key 'header'
"header::tag" | [:] | true
// logs warning: Illegal empty key at position 0
":tag" | [:] | true
// logs warning: Illegal empty key at position 11
"header:tag,:tag" | [:] | true
}
}