From fdf6a9cc2bcbbf718f7c30592076aa758b960cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Thu, 4 Aug 2022 13:52:04 +0200 Subject: [PATCH] Test appending to empty file --- pkg/commands/oscommands/os_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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) } }