diff options
author | Luka Markušić <luka.markusic@microblink.com> | 2022-08-04 13:52:04 +0200 |
---|---|---|
committer | Luka Markušić <luka.markusic@microblink.com> | 2022-08-04 13:52:04 +0200 |
commit | fdf6a9cc2bcbbf718f7c30592076aa758b960cf1 (patch) | |
tree | ee33e20e2d0743b10a2c3117dc868c01b38d5ed4 /pkg | |
parent | 57f86b8f907e73a9c314536443d9d0e76461db90 (diff) |
Test appending to empty file
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/oscommands/os_test.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index abbdc9068..969224405 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -142,6 +142,7 @@ func TestOSCommandAppendLineToFile(t *testing.T) { type scenario struct { path string setup func(string) + test func(string) } scenarios := []scenario{ @@ -152,6 +153,20 @@ func TestOSCommandAppendLineToFile(t *testing.T) { 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"), @@ -160,6 +175,9 @@ func TestOSCommandAppendLineToFile(t *testing.T) { panic(err) } }, + func(output string) { + assert.EqualValues(t, "hello\nworld\n", output) + }, }, } @@ -173,7 +191,7 @@ func TestOSCommandAppendLineToFile(t *testing.T) { if err != nil { panic(err) } - assert.EqualValues(t, "hello\nworld\n", string(f)) + s.test(string(f)) _ = os.RemoveAll(s.path) } } |