summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAnthony HAMON <hamon.anth@gmail.com>2018-09-18 20:47:40 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-09-20 09:09:37 +0200
commit9481920101c7f8e29875e6db2642fe2b317564f9 (patch)
treed0d08707706989d62dbe9a38515f75a28adc61f0 /pkg
parent7b90d2496b56d89863b552b226f45b8de2bd1551 (diff)
commands/git : add test to GetLog
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 790a34690..ba2696e5d 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -1553,6 +1553,48 @@ func TestGitCommandGetCommits(t *testing.T) {
}
}
+func TestGitCommandGetLog(t *testing.T) {
+ type scenario struct {
+ testName string
+ command func(string, ...string) *exec.Cmd
+ test func(string)
+ }
+
+ scenarios := []scenario{
+ {
+ "Retrieves logs",
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"log", "--oneline", "-30"}, args)
+
+ return exec.Command("echo", "6f0b32f commands/git : add GetCommits tests refactor\n9d9d775 circle : remove new line")
+ },
+ func(output string) {
+ assert.EqualValues(t, "6f0b32f commands/git : add GetCommits tests refactor\n9d9d775 circle : remove new line\n", output)
+ },
+ },
+ {
+ "An error occurred when retrieving logs",
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"log", "--oneline", "-30"}, args)
+ return exec.Command("test")
+ },
+ func(output string) {
+ assert.Empty(t, output)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ t.Run(s.testName, func(t *testing.T) {
+ gitCmd := newDummyGitCommand()
+ gitCmd.OSCommand.command = s.command
+ s.test(gitCmd.GetLog())
+ })
+ }
+}
+
func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))