@@ -25,6 +25,9 @@ func TestApply(t *testing.T) {
25
25
User : null .StringFrom ("user" ),
26
26
Password : null .StringFrom ("pass" ),
27
27
FlushPeriod : types .NullDurationFrom (10 * time .Second ),
28
+ Headers : map [string ]string {
29
+ "X-Header" : "value" ,
30
+ },
28
31
}
29
32
30
33
// Defaults should be overwritten by valid values
@@ -36,6 +39,7 @@ func TestApply(t *testing.T) {
36
39
assert .Equal (t , fullConfig .User , c .User )
37
40
assert .Equal (t , fullConfig .Password , c .Password )
38
41
assert .Equal (t , fullConfig .FlushPeriod , c .FlushPeriod )
42
+ assert .Equal (t , fullConfig .Headers , c .Headers )
39
43
40
44
// Defaults shouldn't be impacted by invalid values
41
45
c = NewConfig ()
@@ -78,6 +82,11 @@ func TestConfigParseArg(t *testing.T) {
78
82
assert .Nil (t , err )
79
83
assert .Equal (t , null .StringFrom ("http://prometheus.remote:3412/write" ), c .Url )
80
84
assert .Equal (t , types .NullDurationFrom (time .Second * 2 ), c .FlushPeriod )
85
+
86
+ c , err = ParseArg ("url=http://prometheus.remote:3412/write,headers.X-Header=value" )
87
+ assert .Nil (t , err )
88
+ assert .Equal (t , null .StringFrom ("http://prometheus.remote:3412/write" ), c .Url )
89
+ assert .Equal (t , map [string ]string {"X-Header" : "value" }, c .Headers )
81
90
}
82
91
83
92
// testing both GetConsolidatedConfig and ConstructRemoteConfig here until it's future config refactor takes shape (k6 #883)
@@ -108,6 +117,7 @@ func TestConstructRemoteConfig(t *testing.T) {
108
117
FlushPeriod : types .NullDurationFrom (defaultFlushPeriod ),
109
118
KeepTags : null .BoolFrom (true ),
110
119
KeepNameTag : null .BoolFrom (false ),
120
+ Headers : make (map [string ]string ),
111
121
},
112
122
errString : "" ,
113
123
remoteConfig : & remote.ClientConfig {
@@ -136,6 +146,7 @@ func TestConstructRemoteConfig(t *testing.T) {
136
146
FlushPeriod : types .NullDurationFrom (defaultFlushPeriod ),
137
147
KeepTags : null .BoolFrom (true ),
138
148
KeepNameTag : null .BoolFrom (false ),
149
+ Headers : make (map [string ]string ),
139
150
},
140
151
errString : "" ,
141
152
remoteConfig : & remote.ClientConfig {
@@ -169,6 +180,112 @@ func TestConstructRemoteConfig(t *testing.T) {
169
180
errString : "strconv.ParseBool" ,
170
181
remoteConfig : nil ,
171
182
},
183
+ "remote_write_with_headers_json" : {
184
+ jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s","mapping":"mapping", "headers":{"X-Header":"value"}}` , u .String ())),
185
+ env : nil ,
186
+ arg : "" ,
187
+ config : Config {
188
+ Mapping : null .NewString ("mapping" , true ),
189
+ Url : null .StringFrom (u .String ()),
190
+ InsecureSkipTLSVerify : null .BoolFrom (true ),
191
+ CACert : null .NewString ("" , false ),
192
+ User : null .NewString ("" , false ),
193
+ Password : null .NewString ("" , false ),
194
+ FlushPeriod : types .NullDurationFrom (defaultFlushPeriod ),
195
+ KeepTags : null .BoolFrom (true ),
196
+ KeepNameTag : null .BoolFrom (false ),
197
+ Headers : map [string ]string {
198
+ "X-Header" : "value" ,
199
+ },
200
+ },
201
+ errString : "" ,
202
+ remoteConfig : & remote.ClientConfig {
203
+ URL : & promConfig.URL {URL : u },
204
+ Timeout : model .Duration (defaultPrometheusTimeout ),
205
+ HTTPClientConfig : promConfig.HTTPClientConfig {
206
+ FollowRedirects : true ,
207
+ TLSConfig : promConfig.TLSConfig {
208
+ InsecureSkipVerify : false ,
209
+ },
210
+ },
211
+ RetryOnRateLimit : false ,
212
+ Headers : map [string ]string {
213
+ "X-Header" : "value" ,
214
+ },
215
+ },
216
+ },
217
+ "remote_write_with_headers_env" : {
218
+ jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s","mapping":"mapping", "headers":{"X-Header":"value"}}` , u .String ())),
219
+ env : map [string ]string {
220
+ "K6_PROMETHEUS_HEADERS_X-Header" : "value_from_env" ,
221
+ },
222
+ arg : "" ,
223
+ config : Config {
224
+ Mapping : null .NewString ("mapping" , true ),
225
+ Url : null .StringFrom (u .String ()),
226
+ InsecureSkipTLSVerify : null .BoolFrom (true ),
227
+ CACert : null .NewString ("" , false ),
228
+ User : null .NewString ("" , false ),
229
+ Password : null .NewString ("" , false ),
230
+ FlushPeriod : types .NullDurationFrom (defaultFlushPeriod ),
231
+ KeepTags : null .BoolFrom (true ),
232
+ KeepNameTag : null .BoolFrom (false ),
233
+ Headers : map [string ]string {
234
+ "X-Header" : "value_from_env" ,
235
+ },
236
+ },
237
+ errString : "" ,
238
+ remoteConfig : & remote.ClientConfig {
239
+ URL : & promConfig.URL {URL : u },
240
+ Timeout : model .Duration (defaultPrometheusTimeout ),
241
+ HTTPClientConfig : promConfig.HTTPClientConfig {
242
+ FollowRedirects : true ,
243
+ TLSConfig : promConfig.TLSConfig {
244
+ InsecureSkipVerify : false ,
245
+ },
246
+ },
247
+ RetryOnRateLimit : false ,
248
+ Headers : map [string ]string {
249
+ "X-Header" : "value_from_env" ,
250
+ },
251
+ },
252
+ },
253
+ "remote_write_with_headers_arg" : {
254
+ jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s","mapping":"mapping", "headers":{"X-Header":"value"}}` , u .String ())),
255
+ env : map [string ]string {
256
+ "K6_PROMETHEUS_HEADERS_X-Header" : "value_from_env" ,
257
+ },
258
+ arg : "headers.X-Header=value_from_arg" ,
259
+ config : Config {
260
+ Mapping : null .NewString ("mapping" , true ),
261
+ Url : null .StringFrom (u .String ()),
262
+ InsecureSkipTLSVerify : null .BoolFrom (true ),
263
+ CACert : null .NewString ("" , false ),
264
+ User : null .NewString ("" , false ),
265
+ Password : null .NewString ("" , false ),
266
+ FlushPeriod : types .NullDurationFrom (defaultFlushPeriod ),
267
+ KeepTags : null .BoolFrom (true ),
268
+ KeepNameTag : null .BoolFrom (false ),
269
+ Headers : map [string ]string {
270
+ "X-Header" : "value_from_arg" ,
271
+ },
272
+ },
273
+ errString : "" ,
274
+ remoteConfig : & remote.ClientConfig {
275
+ URL : & promConfig.URL {URL : u },
276
+ Timeout : model .Duration (defaultPrometheusTimeout ),
277
+ HTTPClientConfig : promConfig.HTTPClientConfig {
278
+ FollowRedirects : true ,
279
+ TLSConfig : promConfig.TLSConfig {
280
+ InsecureSkipVerify : false ,
281
+ },
282
+ },
283
+ RetryOnRateLimit : false ,
284
+ Headers : map [string ]string {
285
+ "X-Header" : "value_from_arg" ,
286
+ },
287
+ },
288
+ },
172
289
}
173
290
174
291
for name , testCase := range testCases {
@@ -198,6 +315,7 @@ func assertConfig(t *testing.T, actual, expected Config) {
198
315
assert .Equal (t , expected .FlushPeriod , actual .FlushPeriod )
199
316
assert .Equal (t , expected .KeepTags , actual .KeepTags )
200
317
assert .Equal (t , expected .KeepNameTag , expected .KeepNameTag )
318
+ assert .Equal (t , expected .Headers , actual .Headers )
201
319
}
202
320
203
321
func assertRemoteConfig (t * testing.T , actual , expected * remote.ClientConfig ) {
0 commit comments