Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 08a2f02

Browse files
committed
Add TestParseArgs test
1 parent fe68df9 commit 08a2f02

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

chromium/browser_type_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io/fs"
55
"net"
66
"path/filepath"
7+
"sort"
78
"testing"
89

910
"github.com/grafana/xk6-browser/common"
@@ -251,3 +252,86 @@ func TestExecutablePath(t *testing.T) {
251252
})
252253
}
253254
}
255+
256+
func TestParseArgs(t *testing.T) {
257+
t.Parallel()
258+
259+
tests := []struct {
260+
name string
261+
flags map[string]any
262+
want []string
263+
}{
264+
{
265+
name: "string_flag_with_value",
266+
flags: map[string]any{
267+
"flag1": "value1",
268+
"flag2": "value2",
269+
},
270+
want: []string{
271+
"--flag1=value1",
272+
"--flag2=value2",
273+
"--remote-debugging-port=0",
274+
},
275+
},
276+
{
277+
name: "string_flag_with_empty_value",
278+
flags: map[string]any{
279+
"flag1": "",
280+
"flag2": "value2",
281+
},
282+
want: []string{
283+
"--flag1",
284+
"--flag2=value2",
285+
"--remote-debugging-port=0",
286+
},
287+
},
288+
{
289+
name: "bool_flag_true",
290+
flags: map[string]any{
291+
"flag1": true,
292+
"flag2": true,
293+
},
294+
want: []string{
295+
"--flag1",
296+
"--flag2",
297+
"--remote-debugging-port=0",
298+
},
299+
},
300+
{
301+
name: "bool_flag_false",
302+
flags: map[string]any{
303+
"flag1": false,
304+
"flag2": true,
305+
},
306+
want: []string{
307+
"--flag2",
308+
"--remote-debugging-port=0",
309+
},
310+
},
311+
{
312+
name: "invalid_flag_type",
313+
flags: map[string]any{
314+
"flag1": 123,
315+
},
316+
want: nil,
317+
},
318+
}
319+
320+
for _, tt := range tests {
321+
tt := tt
322+
t.Run(tt.name, func(t *testing.T) {
323+
t.Parallel()
324+
325+
got, err := parseArgs(tt.flags)
326+
327+
if tt.want == nil {
328+
assert.Error(t, err)
329+
return
330+
}
331+
require.NoError(t, err)
332+
sort.StringSlice(tt.want).Sort()
333+
sort.StringSlice(got).Sort()
334+
assert.Equal(t, tt.want, got)
335+
})
336+
}
337+
}

0 commit comments

Comments
 (0)