1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

better interface

This commit is contained in:
Jesse Duffield 2020-10-04 21:57:58 +11:00
parent b64c6a3ac7
commit 778ca8e6f9
5 changed files with 94 additions and 63 deletions

View File

@ -8,7 +8,6 @@ import (
"path/filepath"
"testing"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/stretchr/testify/assert"
)
@ -32,7 +31,7 @@ import (
type integrationTest struct {
name string
prepare func(rootDir string) error
fixture string
}
func generateSnapshot(t *testing.T) string {
@ -61,17 +60,17 @@ func findOrCreateDir(path string) {
func Test(t *testing.T) {
tests := []integrationTest{
// {
// name: "commit",
// prepare: createFixture1,
// },
// {
// name: "squash",
// prepare: createFixture2,
// },
{
name: "commit",
fixture: "newFile",
},
{
name: "squash",
fixture: "manyCommits",
},
{
name: "patchBuilding",
prepare: createFixture3,
fixture: "updatedFile",
},
}
@ -96,7 +95,7 @@ func Test(t *testing.T) {
prepareIntegrationTestDir()
err = test.prepare(rootDir)
err = createFixture(rootDir, test.fixture)
assert.NoError(t, err)
record := os.Getenv("RECORD_EVENTS") != ""
@ -120,41 +119,9 @@ func Test(t *testing.T) {
}
}
func createFixture1() error {
cmds := []string{
"git init",
`sh -c "echo test > myfile"`,
}
return runCommands(cmds)
}
func createFixture2() error {
cmds := []string{
"git init",
`sh -c "echo test1 > myfile1"`,
`git add .`,
`git commit -am "myfile1"`,
`sh -c "echo test2 > myfile2"`,
`git add .`,
`git commit -am "myfile2"`,
`sh -c "echo test3 > myfile3"`,
`git add .`,
`git commit -am "myfile3"`,
`sh -c "echo test4 > myfile4"`,
`git add .`,
`git commit -am "myfile4"`,
`sh -c "echo test5 > myfile5"`,
`git add .`,
`git commit -am "myfile5"`,
}
return runCommands(cmds)
}
func createFixture3(rootDir string) error {
func createFixture(rootDir string, name string) error {
osCommand := oscommands.NewDummyOSCommand()
cmd := exec.Command("sh", filepath.Join(rootDir, "test", "fixtures", "1.sh"))
cmd := exec.Command("sh", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name)))
if err := osCommand.RunExecutable(cmd); err != nil {
return err
@ -163,18 +130,6 @@ func createFixture3(rootDir string) error {
return nil
}
func runCommands(cmds []string) error {
osCommand := oscommands.NewDummyOSCommand()
for _, cmd := range cmds {
if err := osCommand.RunCommand(cmd); err != nil {
return errors.New(fmt.Sprintf("error running command `%s`: %v", cmd, err))
}
}
return nil
}
func gotoRootDirectory() {
for {
_, err := os.Stat(".git")

17
test/fixtures/manyCommits.sh vendored Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
git init
echo test1 > myfile1
git add .
git commit -am "myfile1"
echo test2 > myfile2
git add .
git commit -am "myfile2"
echo test3 > myfile3
git add .
git commit -am "myfile3"
echo test4 > myfile4
git add .
git commit -am "myfile4"
echo test5 > myfile5
git add .
git commit -am "myfile5"

15
test/fixtures/newFile.sh vendored Normal file
View File

@ -0,0 +1,15 @@
#!/bin/sh
git init
echo test1 > myfile1
git add .
git commit -am "myfile1"
echo test2 > myfile2
git add .
git commit -am "myfile2"
echo test3 > myfile3
git add .
git commit -am "myfile3"
echo test4 > myfile4
git add .
git commit -am "myfile4"
echo test5 > myfile5

View File

@ -1,13 +1,57 @@
On branch master
nothing to commit, working tree clean
test
test1
test2
test3
test4
test5
my commit
diff --git a/myfile b/myfile
diff --git a/myfile5 b/myfile5
new file mode 100644
index 0000000..9daeafb
index 0000000..4f346f1
--- /dev/null
+++ b/myfile
+++ b/myfile5
@@ -0,0 +1 @@
+test
+test5
myfile4
diff --git a/myfile4 b/myfile4
new file mode 100644
index 0000000..d234c5e
--- /dev/null
+++ b/myfile4
@@ -0,0 +1 @@
+test4
myfile3
diff --git a/myfile3 b/myfile3
new file mode 100644
index 0000000..df6b0d2
--- /dev/null
+++ b/myfile3
@@ -0,0 +1 @@
+test3
myfile2
diff --git a/myfile2 b/myfile2
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/myfile2
@@ -0,0 +1 @@
+test2
myfile1
diff --git a/myfile1 b/myfile1
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/myfile1
@@ -0,0 +1 @@
+test1