Don't hide there error when it's not about file not existing

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2022-11-23 14:53:02 +02:00
parent 7d077c9353
commit bb144f204a
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3
2 changed files with 13 additions and 0 deletions

View File

@ -127,6 +127,8 @@ func createInfoFileIfNotExists(fileName string) (bool, error) {
return false, err
}
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}

View File

@ -38,6 +38,17 @@ var _ = Describe("Partition Info file parsing", func() {
fmt.Sprintf("partition-info-%d.yaml", time.Now().UnixNano()))
})
When("there is some error other than the file doesn't exist", func() {
It("returns 'false' and the error", func() {
// We are trying to write to a path that doesn't exist (not the file, the path).
// https://stackoverflow.com/a/66808328
fileName = "\000x"
_, _, err := pi.NewPartitionInfoFromFile(fileName)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("stat \000x: invalid argument"))
})
})
It("creates the file and returns 'false' and a non nil mapping", func() {
result, existed, err := pi.NewPartitionInfoFromFile(fileName)
Expect(err).ToNot(HaveOccurred())