-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgg.bats
259 lines (221 loc) · 5.65 KB
/
gg.bats
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env bats
load 'lib/bats-support/load'
load 'lib/bats-assert/load'
TMP_DIRECTORY=$(mktemp -d)
# Setup git repo in temp dir to test functions against
# --------------------------------------------------------------------
setup() {
cd $TMP_DIRECTORY
echo 'setting up'
gg i
git config user.email "[email protected]"
git config user.name "gg test"
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master
echo "test file" > test_file
git add -A
git commit -m "test commit"
}
# If tests pass delete temp git repo
# --------------------------------------------------------------------
teardown() {
if [ $BATS_TEST_COMPLETED ]; then
echo "Deleting $TMP_DIRECTORY"
rm -rf $TMP_DIRECTORY
else
echo "** Did not delete $TMP_DIRECTORY, as test failed **"
fi
cd $BATS_TEST_DIRNAME
}
# The tests
# --------------------------------------------------------------------
@test "Invoke: no param prints help" {
run gg
assert_success
assert_line --partial "simple git aliases"
}
@test "Status" {
run gg s
assert_success
assert_line --partial "On branch master"
}
@test "Add: all files" {
run touch test1.md
run gg a
assert_success
assert_line --partial "Added all files"
assert_line --partial "new file: test1.md"
}
@test "Add: specfic file" {
run touch test2.md
run gg a test2.md
assert_success
assert_line --partial "Added: test2.md"
assert_line --partial "new file: test2.md"
}
@test "Checkout: no param" {
run gg ch
assert_failure
assert_line --partial "Missing parameter: thing to checkout"
}
@test "Checkout: branch" {
git branch test
run gg ch test
assert_line --partial "Switched to branch 'test'"
}
@test "Pull" {
run gg pl
assert_success
assert_line --partial "git-pull"
}
# TODO: Learn how to test interactive input
# @test "Checkout Pull Rebase" {
# # Setup
# gg b test
# gg ch master
# echo "test file 2" > test_file2
# git add test_file2
# git commit -m "test commit 2"
# gg ch test
# # Assert
# run gg cpr
# assert_success
# }
@test "Push" {
run gg p
assert_success
assert_line --partial "Could not read from remote repository."
}
@test "Force Push" {
run gg pf
assert_success
assert_line --partial "Strap in, we're force pushing..."
}
@test "Log" {
run gg l
assert_success
assert_line --partial "test commit"
}
@test "Latest commit message" {
run gg lc
assert_success
assert_line --partial "test commit"
}
# TODO: Learn how to test interactive input
# @test "Rebase" {
# run gg r
# assert_failure
# assert_line --partial "Missing parameter: thing to checkout"
# }
# @test "Rebase: no param" {
# run gg r
# assert_failure
# assert_line --partial "Missing parameter: thing to checkout"
# }
@test "Stash" {
echo "test file 2" > test_file2
run gg st
assert_success
assert_line --partial "Saved working directory"
}
@test "Stash Pop" {
echo "test file 2" > test_file2
gg st
run gg stp
assert_success
assert_line --partial "new file: test_file2"
}
@test "Branch" {
run gg b test
assert_success
assert_line --partial "Switched to a new branch 'test'"
}
@test "Branch: no param" {
run gg b
assert_success
assert_line --partial "All Branches:"
}
@test "Branch delete" {
git branch test
run gg bd test
assert_success
assert_line --partial "Deleted branch test"
}
@test "Branch delete: no param" {
run gg bd
assert_failure
assert_line --partial "Missing parameter: branch name to delete"
}
@test "Github: Pull Request" {
git remote add origin https://github.com/csi-lk/gg
run gg pr
assert_success
assert_line --partial "Opening pull request for branch: master"
}
@test "Gitlab: Pull Request" {
git remote add origin [email protected]:csilk/gg.git
run gg pr
assert_success
assert_line --partial "Opening pull request for branch: master"
}
@test "Github: Open URL" {
git remote add origin https://github.com/csi-lk/gg
run gg o
assert_success
assert_line --partial "Opening repo url: https://github.com/csi-lk/gg"
}
@test "Gitlab: Open URL" {
git remote add origin [email protected]:csilk/gg.git
run gg o
assert_success
assert_line --partial "Opening repo url: https://gitlab.com/csilk/gg"
}
@test "Pull request log" {
git branch prl
run gg ch prl
echo "test prl" > test_prl
run gg a
run git commit -m "feat: test adding commit" -m "commit body" -m "TICKET-123"
run gg prl
assert_success
assert_line --partial "Log output for PR..."
assert_line --partial "feat:"
assert_line --partial "commit body"
assert_line --partial "TICKET"
assert_line --partial "Copied to clipboard"
}
@test "Tag create" {
git remote add origin https://github.com/csi-lk/gg
run gg t test-tag
assert_success
run gg t
assert_line --partial "test-tag"
}
@test "Tag delete" {
git remote add origin https://github.com/csi-lk/gg
run gg t test-tag
assert_success
run gg td test-tag
assert_success
assert_line --partial "Deleted tag 'test-tag'"
}
@test "Tag delete: no param" {
git remote add origin https://github.com/csi-lk/gg
run gg td
assert_failure
assert_line --partial "Missing parameter: tag name to delete"
}
@test "Display Help" {
run gg -h
assert_success
assert_line --partial "simple git aliases"
}
@test "Unknown Command" {
run gg test
assert_failure
assert_line --partial "Unknown command: 'test'"
}
@test "Clean" {
run gg clean
assert_success
assert_line --partial "All Branches:"
}