@@ -63,12 +63,10 @@ func TestConfigParseArg(t *testing.T) {
63
63
assert .Nil (t , err )
64
64
assert .Equal (t , null .StringFrom ("https://prometheus.remote:3412/write" ), c .URL )
65
65
66
- c , err = ParseArg ("url=https://prometheus.remote:3412/write,insecureSkipTLSVerify=false,user=user,password=pass " )
66
+ c , err = ParseArg ("url=https://prometheus.remote:3412/write,insecureSkipTLSVerify=false" )
67
67
assert .Nil (t , err )
68
68
assert .Equal (t , null .StringFrom ("https://prometheus.remote:3412/write" ), c .URL )
69
69
assert .Equal (t , null .BoolFrom (false ), c .InsecureSkipTLSVerify )
70
- assert .Equal (t , null .StringFrom ("user" ), c .Username )
71
- assert .Equal (t , null .StringFrom ("pass" ), c .Password )
72
70
73
71
c , err = ParseArg ("url=http://prometheus.remote:3412/write,pushInterval=2s" )
74
72
assert .Nil (t , err )
@@ -153,9 +151,9 @@ func TestConfigConsolidation(t *testing.T) {
153
151
},
154
152
},
155
153
"mixed_success" : {
156
- jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s","mapping":"raw" }` , u .String ())),
154
+ jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s"}` , u .String ())),
157
155
env : map [string ]string {"K6_PROMETHEUS_INSECURE_SKIP_TLS_VERIFY" : "false" , "K6_PROMETHEUS_USER" : "u" },
158
- arg : "user =user" ,
156
+ arg : "username =user" ,
159
157
config : Config {
160
158
URL : null .StringFrom (u .String ()),
161
159
InsecureSkipTLSVerify : null .BoolFrom (false ),
@@ -247,3 +245,36 @@ func TestConfigConsolidation(t *testing.T) {
247
245
})
248
246
}
249
247
}
248
+
249
+ func TestConfigBasicAuth (t * testing.T ) {
250
+ t .Parallel ()
251
+
252
+ cases := map [string ]struct {
253
+ arg string
254
+ env map [string ]string
255
+ jsonRaw json.RawMessage
256
+ }{
257
+ "JSON" : {jsonRaw : json .RawMessage (`{"username":"user1","password":"pass1"}` )},
258
+ "Env" : {env : map [string ]string {"K6_PROMETHEUS_USERNAME" : "user1" , "K6_PROMETHEUS_PASSWORD" : "pass1" }},
259
+ "Arg" : {arg : "username=user1,password=pass1" },
260
+ }
261
+
262
+ expconfig := Config {
263
+ URL : null .StringFrom ("http://localhost:9090/api/v1/write" ),
264
+ InsecureSkipTLSVerify : null .BoolFrom (true ),
265
+ Username : null .StringFrom ("user1" ),
266
+ Password : null .StringFrom ("pass1" ),
267
+ PushInterval : types .NullDurationFrom (5 * time .Second ),
268
+ Headers : make (map [string ]string ),
269
+ }
270
+
271
+ for name , tc := range cases {
272
+ tc := tc
273
+ t .Run (name , func (t * testing.T ) {
274
+ c , err := GetConsolidatedConfig (
275
+ tc .jsonRaw , tc .env , tc .arg )
276
+ require .NoError (t , err )
277
+ assert .Equal (t , expconfig , c )
278
+ })
279
+ }
280
+ }
0 commit comments