Skip to content

Commit

Permalink
fix: liniting issues, error returned from LoadFromStrings isn't checked
Browse files Browse the repository at this point in the history
  • Loading branch information
RawanMostafa08 committed Sep 24, 2024
1 parent 2691c50 commit 3232742
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/iniparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (i Parser) LoadFromFile(path string) error {
if err != nil {
return ErrFileNotExist
}
i.LoadFromString(string(data))
err = i.LoadFromString(string(data))
if err != nil {
return err
}
return nil
}

Expand Down
24 changes: 18 additions & 6 deletions pkg/iniparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func TestLoadFromString(t *testing.T) {
t.Run("test normal ini file", func(t *testing.T) {

parser := NewParser()
parser.LoadFromString(stringINI)
err := parser.LoadFromString(stringINI)
if err != nil {
t.Error(err)
}

expected := populateExpectedNormal(t)

Expand All @@ -94,7 +97,10 @@ func TestLoadFromString(t *testing.T) {
[database]`
parser := NewParser()
parser.LoadFromString(emptySectionINI)
err := parser.LoadFromString(emptySectionINI)
if err != nil {
t.Error(err)
}

expected := populateExpectedEmptySection(t)

Expand Down Expand Up @@ -178,7 +184,7 @@ func TestGetSectionNames(t *testing.T) {
parser := NewParser()
err := parser.LoadFromString("")
if err != nil {
t.Errorf("Error! %v", err)
t.Error(err)
}
names, err := parser.GetSectionNames()

Expand Down Expand Up @@ -211,7 +217,7 @@ func TestGetSections(t *testing.T) {
parser := NewParser()
err := parser.LoadFromString("")
if err != nil {
t.Errorf("Error! %v", err)
t.Error(err)
}
names, err := parser.GetSections()

Expand Down Expand Up @@ -321,10 +327,16 @@ func TestString(t *testing.T) {
parser1 := NewParser()
parser2 := NewParser()

parser1.LoadFromString(stringINI)
err := parser1.LoadFromString(stringINI)
if err != nil {
t.Error(err)
}
got := parser1.String()

parser2.LoadFromString(got)
err = parser2.LoadFromString(got)
if err != nil {
t.Error(err)
}

assertEquality(t, parser1.sections, parser2.sections)
assertEquality(t, fmt.Sprint(parser1), fmt.Sprint(parser2))
Expand Down

0 comments on commit 3232742

Please sign in to comment.