1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00

Add AppendLineToFile tests

This commit is contained in:
Luka Markušić 2022-08-02 23:46:02 +02:00
parent 86d5654d20
commit d238d8952b

View File

@ -1,6 +1,7 @@
package oscommands
import (
"io/ioutil"
"os"
"testing"
@ -135,3 +136,43 @@ func TestOSCommandFileType(t *testing.T) {
_ = os.RemoveAll(s.path)
}
}
func TestOSCommandAppendLineToFile(t *testing.T) {
type scenario struct {
path string
setup func(string)
}
scenarios := []scenario{
{
"testFile",
func(path string) {
if err := ioutil.WriteFile(path, []byte("hello"), 0o600); err != nil {
panic(err)
}
},
},
{
"testFileWithNewline",
func(path string) {
if err := ioutil.WriteFile(path, []byte("hello\n"), 0o600); err != nil {
panic(err)
}
},
},
}
for _, s := range scenarios {
s.setup(s.path)
osCommand := NewDummyOSCommand()
if err := osCommand.AppendLineToFile(s.path, "world"); err != nil {
panic(err)
}
f, err := ioutil.ReadFile(s.path)
if err != nil {
panic(err)
}
assert.EqualValues(t, "hello\nworld\n", string(f))
_ = os.RemoveAll(s.path)
}
}