summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAnthony HAMON <anthony.hamon@iadvize.com>2018-08-27 23:20:44 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-08-29 12:03:32 +0200
commit85012dbc8f8e767076e1ea906eb2498beb6d96bf (patch)
tree29b31ef4b27fe125b7790f9424dc7b5e5d4af87f /pkg
parent13f90735522d55d83c724aa949dcef3061da290e (diff)
add tests for GetStatusFiles
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index d8df7b4b0..f77c2a3b9 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -84,6 +84,83 @@ func TestGetStashEntryDiff(t *testing.T) {
assert.NoError(t, err)
}
+func TestGetStatusFiles(t *testing.T) {
+ type scenario struct {
+ command func(string, ...string) *exec.Cmd
+ test func([]File)
+ }
+
+ scenarios := []scenario{
+ {
+ func(cmd string, args ...string) *exec.Cmd {
+ return exec.Command("echo")
+ },
+ func(files []File) {
+ assert.Len(t, files, 0)
+ },
+ },
+ {
+ func(cmd string, args ...string) *exec.Cmd {
+ return exec.Command(
+ "echo",
+ "MM file1.txt\nA file3.txt\nAM file2.txt\n?? file4.txt",
+ )
+ },
+ func(files []File) {
+ assert.Len(t, files, 4)
+
+ expected := []File{
+ {
+ Name: "file1.txt",
+ HasStagedChanges: true,
+ HasUnstagedChanges: true,
+ Tracked: true,
+ Deleted: false,
+ HasMergeConflicts: false,
+ DisplayString: "MM file1.txt",
+ },
+ {
+ Name: "file3.txt",
+ HasStagedChanges: true,
+ HasUnstagedChanges: false,
+ Tracked: false,
+ Deleted: false,
+ HasMergeConflicts: false,
+ DisplayString: "A file3.txt",
+ },
+ {
+ Name: "file2.txt",
+ HasStagedChanges: true,
+ HasUnstagedChanges: true,
+ Tracked: false,
+ Deleted: false,
+ HasMergeConflicts: false,
+ DisplayString: "AM file2.txt",
+ },
+ {
+ Name: "file4.txt",
+ HasStagedChanges: false,
+ HasUnstagedChanges: true,
+ Tracked: false,
+ Deleted: false,
+ HasMergeConflicts: false,
+ DisplayString: "?? file4.txt",
+ },
+ }
+
+ assert.EqualValues(t, expected, files)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ gitCmd := newDummyGitCommand()
+ gitCmd.OSCommand.command = s.command
+
+ s.test(gitCmd.GetStatusFiles())
+ }
+}
+
func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))