Test appending to empty file

This commit is contained in:
Luka Markušić 2022-08-04 13:52:04 +02:00
parent 57f86b8f90
commit fdf6a9cc2b

View file

@ -142,6 +142,7 @@ func TestOSCommandAppendLineToFile(t *testing.T) {
type scenario struct { type scenario struct {
path string path string
setup func(string) setup func(string)
test func(string)
} }
scenarios := []scenario{ scenarios := []scenario{
@ -152,6 +153,20 @@ func TestOSCommandAppendLineToFile(t *testing.T) {
panic(err) panic(err)
} }
}, },
func(output string) {
assert.EqualValues(t, "hello\nworld\n", output)
},
},
{
filepath.Join(os.TempDir(), "emptyTestFile"),
func(path string) {
if err := ioutil.WriteFile(path, []byte(""), 0o600); err != nil {
panic(err)
}
},
func(output string) {
assert.EqualValues(t, "world\n", output)
},
}, },
{ {
filepath.Join(os.TempDir(), "testFileWithNewline"), filepath.Join(os.TempDir(), "testFileWithNewline"),
@ -160,6 +175,9 @@ func TestOSCommandAppendLineToFile(t *testing.T) {
panic(err) panic(err)
} }
}, },
func(output string) {
assert.EqualValues(t, "hello\nworld\n", output)
},
}, },
} }
@ -173,7 +191,7 @@ func TestOSCommandAppendLineToFile(t *testing.T) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
assert.EqualValues(t, "hello\nworld\n", string(f)) s.test(string(f))
_ = os.RemoveAll(s.path) _ = os.RemoveAll(s.path)
} }
} }