Skip to content

Commit

Permalink
test(opflags): write more test cases for OpFlags.parseYaml()
Browse files Browse the repository at this point in the history
  • Loading branch information
tgragnato committed Nov 28, 2024
1 parent c894a54 commit e048a84
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions opflags/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@ import (
func TestParseYaml(t *testing.T) {
t.Parallel()

o := &OpFlags{
tests := []struct {
name string
ConfigFilePath string
expectError bool
}{{
name: "ValidConfigFilePath",
ConfigFilePath: "../doc/config.example.yml",
expectError: false,
}, {
name: "EmptyConfigFilePath",
ConfigFilePath: "",
expectError: false,
}, {
name: "InvalidConfigFilePath",
ConfigFilePath: "invalid-path",
expectError: true,
},
}

if err := o.parseYaml(); err != nil {
t.Fatal(err)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &OpFlags{
ConfigFilePath: tt.ConfigFilePath,
}
if err := o.parseYaml(); (err != nil) != tt.expectError {
t.Errorf("OpFlags.parseYaml() error = %v, expectError %v", err, tt.expectError)
}
})
}
}

0 comments on commit e048a84

Please sign in to comment.