Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5d3d5373
Commit
5d3d5373
authored
9 years ago
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out 'run or fail' test pattern
parent
29d303c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
16 deletions
+11
-16
main_test.go
main_test.go
+11
-16
No files found.
main_test.go
View file @
5d3d5373
...
...
@@ -42,10 +42,7 @@ func TestAllowedClone(t *testing.T) {
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
path
.
Join
(
scratchDir
,
"test"
))
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
runOrFail
(
t
,
cloneCmd
)
}
func
TestAllowedPush
(
t
*
testing
.
T
)
{
...
...
@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) {
t
.
Fatal
(
err
)
}
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
runOrFail
(
t
,
cloneCmd
)
branch
:=
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
branchCmd
:=
exec
.
Command
(
"git"
,
"branch"
,
branch
)
branchCmd
.
Dir
=
checkoutDir
if
out
,
err
:=
branchCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
runOrFail
(
t
,
branchCmd
)
// Prepare the test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
...
...
@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) {
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
pushCmd
.
Dir
=
checkoutDir
if
out
,
err
:=
pushCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
runOrFail
(
t
,
pushCmd
)
}
func
testAuthServer
(
code
int
,
body
string
)
*
httptest
.
Server
{
...
...
@@ -114,3 +102,10 @@ func waitServer() (err error) {
}
return
}
func
runOrFail
(
t
*
testing
.
T
,
cmd
*
exec
.
Cmd
)
{
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment