Propagate errors encountered when reading file

This commit is contained in:
Martin Milata 2016-12-12 14:41:36 +01:00
parent 4ed13390c0
commit 0ff0c0fc7a
2 changed files with 13 additions and 0 deletions

View File

@ -143,6 +143,10 @@ func readFile(filename string) (envMap map[string]string, err error) {
lines = append(lines, scanner.Text())
}
if err = scanner.Err(); err != nil {
return
}
for _, fullLine := range lines {
if !isIgnoredLine(fullLine) {
key, value, err := parseLine(fullLine)

View File

@ -269,3 +269,12 @@ func TestLinesToIgnore(t *testing.T) {
t.Error("ignoring a perfectly valid line to parse")
}
}
func TestErrorReadDirectory(t *testing.T) {
envFileName := "fixtures/"
envMap, err := Read(envFileName)
if err == nil {
t.Errorf("Expected error, got %v", envMap)
}
}