diff --git a/pkg/iniparser_test.go b/pkg/iniparser_test.go index 63e3815..b9b32fa 100644 --- a/pkg/iniparser_test.go +++ b/pkg/iniparser_test.go @@ -113,16 +113,45 @@ func TestLoadFromString(t *testing.T) { func TestLoadFromFile(t *testing.T) { - expected := populateExpectedNormal(t) - - parser := InitParser() + expectedFile := populateExpectedNormal(t) - err := parser.LoadFromFile(path) - if err != nil { - t.Errorf("Error! %v", err) + testcases := []struct { + testcaseName string + filePath string + expected map[string]section + err error + }{ + { + testcaseName: "Normal case: ini file is present", + filePath: "testdata/file.ini", + expected: expectedFile, + err: nil, + }, + { + testcaseName: "corner case: not an ini file", + filePath: "testdata/file.txt", + err: fmt.Errorf("this is not an ini file"), + }, + { + testcaseName: "corner case: file not found", + filePath: "testdata/filex.ini", + err: fmt.Errorf("error in reading the file: open testdata/filex.ini: no such file or directory"), + }, } + for _, testcase := range testcases { + + t.Run(testcase.testcaseName, func(t *testing.T) { + parser := InitParser() - assertEquality(t, expected, parser.sections) + err := parser.LoadFromFile(testcase.filePath) + if testcase.err == nil { + assertEquality(t, expectedFile, parser.sections) + } else { + assertEquality(t, testcase.err, err) + } + + }) + } } func TestGetSectionNames(t *testing.T) {