summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAnthony HAMON <anthony.hamon@iadvize.com>2018-08-28 20:55:14 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-08-29 12:03:32 +0200
commitd6b4d4b063e4def1fbdeea5a90e31cdb2fb1a00b (patch)
tree19af289eac56b214cdf8418973a9c49bfed97450 /pkg
parent45fa2571287ac45045b9d6127dc0a38538b4fa4f (diff)
add tests for MergesStatusFiles
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go4
-rw-r--r--pkg/commands/git_test.go75
2 files changed, 77 insertions, 2 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 5a4d910d3..0cedb2150 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -121,10 +121,10 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File {
return newFiles
}
- appendedIndexes := make([]int, 0)
+ appendedIndexes := []int{}
// retain position of files we already could see
- result := make([]File, 0)
+ result := []File{}
for _, oldFile := range oldFiles {
for newIndex, newFile := range newFiles {
if oldFile.Name == newFile.Name {
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 920f527a8..2380887e1 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -185,6 +185,81 @@ func TestGitCommandStashSave(t *testing.T) {
assert.NoError(t, gitCmd.StashSave("A stash message"))
}
+func TestGitCommandMergeStatusFiles(t *testing.T) {
+ type scenario struct {
+ oldFiles []File
+ newFiles []File
+ test func([]File)
+ }
+
+ scenarios := []scenario{
+ {
+ []File{},
+ []File{
+ {
+ Name: "new_file.txt",
+ },
+ },
+ func(files []File) {
+ expected := []File{
+ {
+ Name: "new_file.txt",
+ },
+ }
+
+ assert.Len(t, files, 1)
+ assert.EqualValues(t, expected, files)
+ },
+ },
+ {
+ []File{
+ {
+ Name: "new_file1.txt",
+ },
+ {
+ Name: "new_file2.txt",
+ },
+ {
+ Name: "new_file3.txt",
+ },
+ },
+ []File{
+ {
+ Name: "new_file4.txt",
+ },
+ {
+ Name: "new_file5.txt",
+ },
+ {
+ Name: "new_file1.txt",
+ },
+ },
+ func(files []File) {
+ expected := []File{
+ {
+ Name: "new_file1.txt",
+ },
+ {
+ Name: "new_file4.txt",
+ },
+ {
+ Name: "new_file5.txt",
+ },
+ }
+
+ assert.Len(t, files, 3)
+ assert.EqualValues(t, expected, files)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ gitCmd := newDummyGitCommand()
+
+ s.test(gitCmd.MergeStatusFiles(s.oldFiles, s.newFiles))
+ }
+}
+
func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))