-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitService_test.go
198 lines (142 loc) · 4.08 KB
/
gitService_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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
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 calling FetchLatest on the current directory", func() {
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
actual := FetchLatest(directory)
g.Assert(actual).Equal(true)
})
g.It("should fail when calling FetchLatest on a directory that does not exist", func() {
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "./foobar"
actual := FetchLatest(directory)
g.Assert(actual).Equal(false)
})
g.It("should call the git command when calling FetchLatest", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
FetchLatest(directory)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
g.It("should call the FetchLatest with the args 'fetch' and '-all'", func() {
expected := []string{"fetch", "--all"}
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
FetchLatest(directory)
actual := passedInArgs
g.Assert(actual).Equal(expected)
})
g.It("should succeed when calling PullLatest on the current directory", func() {
execCommand = fakeExecCommand
defer func() { execCommand = exec.Command }()
directory := "."
actual := PullLatest(directory)
g.Assert(actual).Equal(true)
})
g.It("should fail when calling PullLatest on a directory that does not exist", func() {
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "./foobar"
actual := PullLatest(directory)
g.Assert(actual).Equal(false)
})
g.It("should call the git command when calling PullLatest", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
PullLatest(directory)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
g.It("should call the PullLatest with the args 'fetch' and '-all'", func() {
expected := []string{"pull", "--all"}
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
PullLatest(directory)
actual := passedInArgs
g.Assert(actual).Equal(expected)
})
g.It("should succeed when calling PushLatest on the current directory", func() {
execCommand = fakeExecCommand
defer func() { execCommand = exec.Command }()
directory := "."
actual := PushLatest(directory)
g.Assert(actual).Equal(true)
})
g.It("should fail when calling PushLatest on a directory that does not exist", func() {
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "./foobar"
actual := PushLatest(directory)
g.Assert(actual).Equal(false)
})
g.It("should call the git command when calling PushLatest", func() {
expected := "git"
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
PushLatest(directory)
actual := passedInCommand
g.Assert(actual).Equal(expected)
})
g.It("should call the PushLatest with the args 'push' 'bitbucket' and '-all'", func() {
expected := []string{"push", "bitbucket", "--all"}
execCommand = fakeExecCommand
defer func() {
execCommand = exec.Command
}()
directory := "."
PushLatest(directory)
actual := passedInArgs
g.Assert(actual).Equal(expected)
})
})
}