Skip to content

Commit

Permalink
test: testcases for LoadFromFile added
Browse files Browse the repository at this point in the history
  • Loading branch information
RawanMostafa08 committed Sep 11, 2024
1 parent 5dbd304 commit 96c7df6
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions pkg/iniparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 96c7df6

Please sign in to comment.