@@ -78,7 +78,6 @@ func TestGenerateHintsMapping(t *testing.T) {
78
78
79
79
expected := mapstr.M {
80
80
"redis" : mapstr.M {
81
- "enabled" : true ,
82
81
"host" : "127.0.0.5:6379" ,
83
82
"metrics_path" : "/metrics" ,
84
83
"username" : "username" ,
@@ -118,6 +117,76 @@ func TestGenerateHintsMapping(t *testing.T) {
118
117
assert .Equal (t , expected , hintsMapping )
119
118
}
120
119
120
+ func TestGenerateHintsMappingWithDefaults (t * testing.T ) {
121
+ logger := getLogger ()
122
+ pod := & kubernetes.Pod {
123
+ ObjectMeta : metav1.ObjectMeta {
124
+ Name : "testpod" ,
125
+ UID : types .UID (uid ),
126
+ Namespace : "testns" ,
127
+ Labels : map [string ]string {
128
+ "foo" : "bar" ,
129
+ "with-dash" : "dash-value" ,
130
+ "with/slash" : "some/path" ,
131
+ },
132
+ Annotations : map [string ]string {
133
+ "app" : "production" ,
134
+ },
135
+ },
136
+ TypeMeta : metav1.TypeMeta {
137
+ Kind : "Pod" ,
138
+ APIVersion : "v1" ,
139
+ },
140
+ Spec : kubernetes.PodSpec {
141
+ NodeName : "testnode" ,
142
+ },
143
+ Status : kubernetes.PodStatus {PodIP : "127.0.0.5" },
144
+ }
145
+
146
+ mapping := map [string ]interface {}{
147
+ "namespace" : pod .GetNamespace (),
148
+ "pod" : mapstr.M {
149
+ "uid" : string (pod .GetUID ()),
150
+ "name" : pod .GetName (),
151
+ "ip" : pod .Status .PodIP ,
152
+ },
153
+ "namespace_annotations" : mapstr.M {
154
+ "nsa" : "nsb" ,
155
+ },
156
+ "labels" : mapstr.M {
157
+ "foo" : "bar" ,
158
+ "with-dash" : "dash-value" ,
159
+ "with/slash" : "some/path" ,
160
+ },
161
+ "annotations" : mapstr.M {
162
+ "app" : "production" ,
163
+ },
164
+ }
165
+ hints := mapstr.M {
166
+ "hints" : mapstr.M {
167
+ "host" : "${kubernetes.pod.ip}:6379" ,
168
+ "package" : "redis" ,
169
+ "metrics_path" : "/metrics" ,
170
+ "timeout" : "42s" ,
171
+ "period" : "42s" ,
172
+ },
173
+ }
174
+
175
+ expected := mapstr.M {
176
+ "redis" : mapstr.M {
177
+ "enabled" : true ,
178
+ "host" : "127.0.0.5:6379" ,
179
+ "metrics_path" : "/metrics" ,
180
+ "timeout" : "42s" ,
181
+ "period" : "42s" ,
182
+ },
183
+ }
184
+
185
+ hintsMapping := GenerateHintsMapping (hints , mapping , logger , "" )
186
+
187
+ assert .Equal (t , expected , hintsMapping )
188
+ }
189
+
121
190
func TestGenerateHintsMappingWithContainerID (t * testing.T ) {
122
191
logger := getLogger ()
123
192
pod := & kubernetes.Pod {
@@ -184,7 +253,6 @@ func TestGenerateHintsMappingWithContainerID(t *testing.T) {
184
253
"container_logs" : mapstr.M {
185
254
"enabled" : true ,
186
255
},
187
- "enabled" : true ,
188
256
"host" : "127.0.0.5:6379" ,
189
257
"metrics_path" : "/metrics" ,
190
258
"username" : "username" ,
@@ -281,7 +349,6 @@ func TestGenerateHintsMappingWithLogStream(t *testing.T) {
281
349
expected := mapstr.M {
282
350
"container_id" : "asdfghjkl" ,
283
351
"apache" : mapstr.M {
284
- "enabled" : true ,
285
352
"container_logs" : mapstr.M {
286
353
"enabled" : true ,
287
354
},
0 commit comments