-
Notifications
You must be signed in to change notification settings - Fork 3
/
git_test.go
135 lines (97 loc) · 2.58 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package services
import (
"os"
"os/exec"
"testing"
. "github.com/franela/goblin"
)
// Command spys
var passedInCommand string
var passedInArgs []string
// From Go's source code
// https://golang.org/src/os/exec/exec_test.go
func fakeExecCommand(command string, args ...string) *exec.Cmd {
passedInCommand = command
passedInArgs = args
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
return cmd
}
func Test_GitService(t *testing.T) {
g := Goblin(t)
g.Describe("Git Service", func() {
g.It("should succeed when tagging the current repository with a version", func() {
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
version := "1.0.3"
actual := Tag(version)
g.Assert(actual).Equal(true)
})
g.It("should call the proper git command when calling Tag", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
version := "1.0.3"
Tag(version)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
g.It("should call Tag with the args 'tag' and the version", func() {
version := "1.0.3"
expected := []string{"tag", version}
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
Tag(version)
actual := passedInArgs
g.Assert(actual).Equal(expected)
})
g.It("should succeed when calling PushTag", func() {
execCommand = fakeExecCommand
defer func() { execCommand = exec.Command }()
version := "1.0.3"
actual := PushTag(version)
g.Assert(actual).Equal(true)
})
g.It("should call the git command when calling PushTag", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
version := "1.0.3"
PushTag(version)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
g.It("should call PushTag with the args 'tag' and the version", func() {
version := "1.0.3"
expected := []string{"push", "--tags"}
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
PushTag(version)
actual := passedInArgs
g.Assert(actual).Equal(expected)
})
g.It("should call the git command when calling TagAndPush", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
version := "1.0.3"
TagAndPush(version)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
})
}