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) } }