Skip to content

Commit d1b9045

Browse files
committed
added tests
1 parent 3e82d10 commit d1b9045

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

pkg/config/config_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,80 @@ func TestMergeDefaultConfig(t *testing.T) {
403403
err = mergeDefaultConfig(v)
404404
assert.NoError(t, err, "should not return error if config type is yaml")
405405
}
406+
407+
func TestParseFlags(t *testing.T) {
408+
tests := []struct {
409+
name string
410+
args []string
411+
expected map[string]string
412+
}{
413+
{
414+
name: "no flags",
415+
args: []string{},
416+
expected: map[string]string{},
417+
},
418+
{
419+
name: "single flag",
420+
args: []string{"--key=value"},
421+
expected: map[string]string{"key": "value"},
422+
},
423+
{
424+
name: "multiple flags",
425+
args: []string{"--key1=value1", "--key2=value2"},
426+
expected: map[string]string{"key1": "value1", "key2": "value2"},
427+
},
428+
}
429+
430+
for _, test := range tests {
431+
t.Run(test.name, func(t *testing.T) {
432+
oldArgs := os.Args
433+
defer func() { os.Args = oldArgs }()
434+
os.Args = test.args
435+
result := parseFlags()
436+
assert.Equal(t, test.expected, result)
437+
})
438+
}
439+
}
440+
441+
func TestSetLogConfig(t *testing.T) {
442+
tests := []struct {
443+
name string
444+
args []string
445+
expectedLogLevel string
446+
expectetdNoColor bool
447+
}{
448+
{
449+
name: "valid log level",
450+
args: []string{"--logs-level", "Debug"},
451+
expectedLogLevel: "Debug",
452+
},
453+
{
454+
name: "invalid log level",
455+
args: []string{"--logs-level", "InvalidLevel"},
456+
expectedLogLevel: "InvalidLevel",
457+
},
458+
{
459+
name: "No color flag",
460+
args: []string{"--no-color"},
461+
expectedLogLevel: "",
462+
expectetdNoColor: true,
463+
},
464+
{
465+
name: "No color flag with log level",
466+
args: []string{"--no-color", "--logs-level", "Debug"},
467+
expectedLogLevel: "Debug",
468+
expectetdNoColor: true,
469+
},
470+
}
471+
472+
for _, test := range tests {
473+
t.Run(test.name, func(t *testing.T) {
474+
oldArgs := os.Args
475+
defer func() { os.Args = oldArgs }()
476+
os.Args = test.args
477+
atmosConfig := &schema.AtmosConfiguration{}
478+
setLogConfig(atmosConfig)
479+
assert.Equal(t, test.expectedLogLevel, atmosConfig.Logs.Level)
480+
})
481+
}
482+
}

0 commit comments

Comments
 (0)