summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-10-07 18:48:34 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-10-10 00:23:01 +1100
commit88f2a66a5125a1488204ef8a91ddb4bf3bb5c69a (patch)
tree0063e499af2c9c10bcb9046e521dea42655ddc51
parentbb081ca764e42a5cfa67a0dd42acbdef4ae57e05 (diff)
store everything you need to know about a test in its directory
-rw-r--r--pkg/gui/gui_test.go87
-rw-r--r--test/integration/commit/setup.sh (renamed from test/fixtures/newFile.sh)0
-rw-r--r--test/integration/commit/test.json1
-rw-r--r--test/integration/mergeConflicts/setup.sh (renamed from test/fixtures/mergeConflicts.sh)0
-rw-r--r--test/integration/mergeConflicts/test.json1
-rw-r--r--test/integration/patchBuilding/setup.sh (renamed from test/fixtures/updatedFile.sh)0
-rw-r--r--test/integration/patchBuilding/test.json1
-rw-r--r--test/integration/patchBuilding2/setup.sh24
-rw-r--r--test/integration/patchBuilding2/test.json1
-rw-r--r--test/integration/searching/setup.sh (renamed from test/fixtures/unstagedFiles.sh)0
-rw-r--r--test/integration/searching/test.json1
-rw-r--r--test/integration/searchingInStagingPanel/setup.sh (renamed from test/fixtures/newFile2.sh)0
-rw-r--r--test/integration/searchingInStagingPanel/test.json1
-rw-r--r--test/integration/squash/setup.sh (renamed from test/fixtures/manyCommits.sh)0
-rw-r--r--test/integration/squash/test.json1
15 files changed, 71 insertions, 47 deletions
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go
index e11151020..fa5599703 100644
--- a/pkg/gui/gui_test.go
+++ b/pkg/gui/gui_test.go
@@ -1,6 +1,7 @@
package gui
import (
+ "encoding/json"
"fmt"
"io"
"io/ioutil"
@@ -8,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
+ "strings"
"testing"
"github.com/creack/pty"
@@ -39,46 +41,32 @@ import (
// original playback speed. Speed must be an integer.
type integrationTest struct {
- name string
- fixture string
- startSpeed int
+ Name string `json:"name"`
+ Speed int `json:"speed"`
+ Description string `json:"description"`
}
-func tests() []integrationTest {
- return []integrationTest{
- {
- name: "commit",
- fixture: "newFile",
- startSpeed: 20,
- },
- {
- name: "squash",
- fixture: "manyCommits",
- startSpeed: 6,
- },
- {
- name: "patchBuilding",
- fixture: "updatedFile",
- startSpeed: 3,
- },
- {
- name: "patchBuilding2",
- fixture: "updatedFile",
- startSpeed: 3,
- },
- {
- name: "mergeConflicts",
- fixture: "mergeConflicts",
- },
- {
- name: "searching",
- fixture: "newFile",
- },
- {
- name: "searchingInStagingPanel",
- fixture: "newFile2",
- },
+func loadTests(t *testing.T, testDir string) []*integrationTest {
+ paths, err := filepath.Glob(filepath.Join(testDir, "/*/test.json"))
+ assert.NoError(t, err)
+
+ tests := make([]*integrationTest, len(paths))
+
+ for i, path := range paths {
+ data, err := ioutil.ReadFile(path)
+ assert.NoError(t, err)
+
+ test := &integrationTest{}
+
+ err = json.Unmarshal(data, test)
+ assert.NoError(t, err)
+
+ test.Name = strings.TrimPrefix(filepath.Dir(path), testDir+"/")
+
+ tests[i] = test
}
+
+ return tests
}
func generateSnapshot(t *testing.T, dir string) string {
@@ -169,9 +157,10 @@ func getTestSpeeds(testStartSpeed int, updateSnapshots bool) []int {
}
func Test(t *testing.T) {
- tests := tests()
-
rootDir := getRootDirectory()
+ testDir := filepath.Join(rootDir, "test", "integration")
+
+ tests := loadTests(t, testDir)
record := os.Getenv("RECORD_EVENTS") != ""
updateSnapshots := record || os.Getenv("UPDATE_SNAPSHOTS") != ""
@@ -179,17 +168,17 @@ func Test(t *testing.T) {
for _, test := range tests {
test := test
- t.Run(test.name, func(t *testing.T) {
+ t.Run(test.Name, func(t *testing.T) {
if runInParallel() {
t.Parallel()
}
- speeds := getTestSpeeds(test.startSpeed, updateSnapshots)
+ speeds := getTestSpeeds(test.Speed, updateSnapshots)
for i, speed := range speeds {
- t.Logf("%s: attempting test at speed %d\n", test.name, speed)
+ t.Logf("%s: attempting test at speed %d\n", test.Name, speed)
- testPath := filepath.Join(rootDir, "test", "integration", test.name)
+ testPath := filepath.Join(testDir, test.Name)
actualDir := filepath.Join(testPath, "actual")
expectedDir := filepath.Join(testPath, "expected")
t.Logf("testPath: %s, actualDir: %s, expectedDir: %s", testPath, actualDir, expectedDir)
@@ -197,7 +186,7 @@ func Test(t *testing.T) {
prepareIntegrationTestDir(actualDir)
- err := createFixture(rootDir, test.fixture, actualDir)
+ err := createFixture(testPath, actualDir)
assert.NoError(t, err)
runLazygit(t, testPath, rootDir, record, speed)
@@ -234,7 +223,7 @@ func Test(t *testing.T) {
}()
if expected == actual {
- t.Logf("%s: success at speed %d\n", test.name, speed)
+ t.Logf("%s: success at speed %d\n", test.Name, speed)
break
}
@@ -247,9 +236,10 @@ func Test(t *testing.T) {
}
}
-func createFixture(rootDir string, name string, actualDir string) error {
+func createFixture(testPath, actualDir string) error {
osCommand := oscommands.NewDummyOSCommand()
- cmd := exec.Command("bash", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name)), actualDir)
+ bashScriptPath := filepath.Join(testPath, "setup.sh")
+ cmd := exec.Command("bash", bashScriptPath, actualDir)
if err := osCommand.RunExecutable(cmd); err != nil {
return err
@@ -311,6 +301,9 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool, spee
cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed))
if record {
+ cmd.Stdout = os.Stdout
+ cmd.Stdin = os.Stdin
+ cmd.Stderr = os.Stderr
cmd.Env = append(
cmd.Env,
fmt.Sprintf("RECORD_EVENTS_TO=%s", replayPath),
diff --git a/test/fixtures/newFile.sh b/test/integration/commit/setup.sh
index 21fb3fefb..21fb3fefb 100644
--- a/test/fixtures/newFile.sh
+++ b/test/integration/commit/setup.sh
diff --git a/test/integration/commit/test.json b/test/integration/commit/test.json
new file mode 100644
index 000000000..906dc342d
--- /dev/null
+++ b/test/integration/commit/test.json
@@ -0,0 +1 @@
+{ "description": "stage a file and commit the change", "speed": 20 }
diff --git a/test/fixtures/mergeConflicts.sh b/test/integration/mergeConflicts/setup.sh
index 0d9a57cf9..0d9a57cf9 100644
--- a/test/fixtures/mergeConflicts.sh
+++ b/test/integration/mergeConflicts/setup.sh
diff --git a/test/integration/mergeConflicts/test.json b/test/integration/mergeConflicts/test.json
new file mode 100644
index 000000000..41e095612
--- /dev/null
+++ b/test/integration/mergeConflicts/test.json
@@ -0,0 +1 @@
+{ "description": "" }
diff --git a/test/fixtures/updatedFile.sh b/test/integration/patchBuilding/setup.sh
index 2e117b4ad..2e117b4ad 100644
--- a/test/fixtures/updatedFile.sh
+++ b/test/integration/patchBuilding/setup.sh
diff --git a/test/integration/patchBuilding/test.json b/test/integration/patchBuilding/test.json
new file mode 100644
index 000000000..a27eda0bf
--- /dev/null
+++ b/test/integration/patchBuilding/test.json
@@ -0,0 +1 @@
+{ "description": "", "speed": 3 }
diff --git a/test/integration/patchBuilding2/setup.sh b/test/integration/patchBuilding2/setup.sh
new file mode 100644
index 000000000..2e117b4ad
--- /dev/null
+++ b/test/integration/patchBuilding2/setup.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+cd $1
+
+git init
+
+git config user.email "CI@example.com"
+git config user.name "CI"
+
+echo test1 > myfile1
+git add .
+git commit -am "myfile1"
+echo firstline > myfile2
+echo secondline >> myfile2
+echo thirdline >> myfile2
+git add .
+git commit -am "myfile2"
+echo firstline2 > myfile2
+echo secondline >> myfile2
+echo thirdline2 >> myfile2
+git commit -am "myfile2 update"
+echo test3 > myfile3
+git add .
+git commit -am "myfile3"
diff --git a/test/integration/patchBuilding2/test.json b/test/integration/patchBuilding2/test.json
new file mode 100644
index 000000000..a27eda0bf
--- /dev/null
+++ b/test/integration/patchBuilding2/test.json
@@ -0,0 +1 @@
+{ "description": "", "speed": 3 }
diff --git a/test/fixtures/unstagedFiles.sh b/test/integration/searching/setup.sh
index 21fb3fefb..21fb3fefb 100644
--- a/test/fixtures/unstagedFiles.sh
+++ b/test/integration/searching/setup.sh
diff --git a/test/integration/searching/test.json b/test/integration/searching/test.json
new file mode 100644
index 000000000..41e095612
--- /dev/null
+++ b/test/integration/searching/test.json
@@ -0,0 +1 @@
+{ "description": "" }
diff --git a/test/fixtures/newFile2.sh b/test/integration/searchingInStagingPanel/setup.sh
index d55861929..d55861929 100644
--- a/test/fixtures/newFile2.sh
+++ b/test/integration/searchingInStagingPanel/setup.sh
diff --git a/test/integration/searchingInStagingPanel/test.json b/test/integration/searchingInStagingPanel/test.json
new file mode 100644
index 000000000..41e095612
--- /dev/null
+++ b/test/integration/searchingInStagingPanel/test.json
@@ -0,0 +1 @@
+{ "description": "" }
diff --git a/test/fixtures/manyCommits.sh b/test/integration/squash/setup.sh
index 15e61f48b..15e61f48b 100644
--- a/test/fixtures/manyCommits.sh
+++ b/test/integration/squash/setup.sh
diff --git a/test/integration/squash/test.json b/test/integration/squash/test.json
new file mode 100644
index 000000000..41e095612
--- /dev/null
+++ b/test/integration/squash/test.json
@@ -0,0 +1 @@
+{ "description": "" }