@@ -63,12 +63,10 @@ func TestConfigParseArg(t *testing.T) {
6363 assert .Nil (t , err )
6464 assert .Equal (t , null .StringFrom ("https://prometheus.remote:3412/write" ), c .URL )
6565
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" )
6767 assert .Nil (t , err )
6868 assert .Equal (t , null .StringFrom ("https://prometheus.remote:3412/write" ), c .URL )
6969 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 )
7270
7371 c , err = ParseArg ("url=http://prometheus.remote:3412/write,pushInterval=2s" )
7472 assert .Nil (t , err )
@@ -153,9 +151,9 @@ func TestConfigConsolidation(t *testing.T) {
153151 },
154152 },
155153 "mixed_success" : {
156- jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s","mapping":"raw" }` , u .String ())),
154+ jsonRaw : json .RawMessage (fmt .Sprintf (`{"url":"%s"}` , u .String ())),
157155 env : map [string ]string {"K6_PROMETHEUS_INSECURE_SKIP_TLS_VERIFY" : "false" , "K6_PROMETHEUS_USER" : "u" },
158- arg : "user =user" ,
156+ arg : "username =user" ,
159157 config : Config {
160158 URL : null .StringFrom (u .String ()),
161159 InsecureSkipTLSVerify : null .BoolFrom (false ),
@@ -247,3 +245,36 @@ func TestConfigConsolidation(t *testing.T) {
247245 })
248246 }
249247}
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