mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
Add AppendLineToFile tests
This commit is contained in:
parent
86d5654d20
commit
d238d8952b
@ -1,6 +1,7 @@
|
|||||||
package oscommands
|
package oscommands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -135,3 +136,43 @@ func TestOSCommandFileType(t *testing.T) {
|
|||||||
_ = os.RemoveAll(s.path)
|
_ = 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user