Fix handling of service files with invalid syntax
This commit is contained in:
committed by
Jack Christensen
parent
3430c5407d
commit
2b9c44734f
+1
-1
@@ -60,7 +60,7 @@ func ParseServicefile(r io.Reader) (*Servicefile, error) {
|
||||
} else {
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
fmt.Errorf("unable to parse line %d", lineNum)
|
||||
return nil, fmt.Errorf("unable to parse line %d", lineNum)
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(parts[0])
|
||||
|
||||
@@ -51,3 +51,11 @@ application_name = has space
|
||||
assert.Equal(t, "defuser", def.Settings["user"])
|
||||
assert.Equal(t, "has space", def.Settings["application_name"])
|
||||
}
|
||||
|
||||
func TestParseServicefileWithInvalidFile(t *testing.T) {
|
||||
buf := bytes.NewBufferString("Invalid syntax\n")
|
||||
|
||||
servicefile, err := pgservicefile.ParseServicefile(buf)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, servicefile)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user