Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
75ba7ebe
Commit
75ba7ebe
authored
Aug 12, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make "go test" work without path helper
parent
4d86b01f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
16 deletions
+125
-16
Makefile
Makefile
+14
-13
_support/path
_support/path
+0
-2
internal/artifacts/artifacts_test.go
internal/artifacts/artifacts_test.go
+23
-0
internal/testhelper/testhelper.go
internal/testhelper/testhelper.go
+77
-0
main_test.go
main_test.go
+11
-1
No files found.
Makefile
View file @
75ba7ebe
PREFIX
=
/usr/local
PREFIX
=
/usr/local
VERSION
=
$(
shell
git describe
)
-
$(
shell
date
-u
+%Y%m%d.%H%M%S
)
VERSION
=
$(
shell
git describe
)
-
$(
shell
date
-u
+%Y%m%d.%H%M%S
)
export
GOPATH
=
$(
shell
pwd
)
/_build
BUILD_DIR
=
$(
shell
pwd
)
export
GOPATH
=
${BUILD_DIR}
/_build
GOBUILD
=
go build
-ldflags
"-X main.Version=
${VERSION}
"
GOBUILD
=
go build
-ldflags
"-X main.Version=
${VERSION}
"
PKG
=
gitlab.com/gitlab-org/gitlab-workhorse
PKG
=
gitlab.com/gitlab-org/gitlab-workhorse
all
:
clean-build gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse
all
:
clean-build gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse
gitlab-zip-cat
:
_build $(shell find cmd/gitlab-zip-cat/ -name '*.go')
gitlab-zip-cat
:
${BUILD_DIR}/
_build $(shell find cmd/gitlab-zip-cat/ -name '*.go')
${GOBUILD}
-o
$@
${PKG}
/cmd/
$@
${GOBUILD}
-o
$
{BUILD_DIR}
/
$
@
${PKG}
/cmd/
$@
gitlab-zip-metadata
:
_build $(shell find cmd/gitlab-zip-metadata/ -name '*.go')
gitlab-zip-metadata
:
${BUILD_DIR}/
_build $(shell find cmd/gitlab-zip-metadata/ -name '*.go')
${GOBUILD}
-o
$@
${PKG}
/cmd/
$@
${GOBUILD}
-o
$
{BUILD_DIR}
/
$
@
${PKG}
/cmd/
$@
gitlab-workhorse
:
_build $(shell find . -name '*.go' | grep -v '^
\.
/_')
gitlab-workhorse
:
${BUILD_DIR}/
_build $(shell find . -name '*.go' | grep -v '^
\.
/_')
${GOBUILD}
-o
$@
${PKG}
${GOBUILD}
-o
$
{BUILD_DIR}
/
$
@
${PKG}
install
:
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
install
:
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
mkdir
-p
$(DESTDIR)${PREFIX}
/bin/
mkdir
-p
$(DESTDIR)${PREFIX}
/bin/
install
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
${DESTDIR}${PREFIX}
/bin/
cd
${BUILD_DIR}
&&
install
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
${DESTDIR}${PREFIX}
/bin/
_build
:
${BUILD_DIR}/
_build
:
mkdir
-p
$@
/src/
${PKG}
mkdir
-p
$@
/src/
${PKG}
tar
-cf
-
--exclude
$@
--exclude
.git
.
|
(
cd
$@
/src/
${PKG}
&&
tar
-xf
-
)
tar
-cf
-
--exclude
_build
--exclude
.git
.
|
(
cd
$@
/src/
${PKG}
&&
tar
-xf
-
)
touch
$@
touch
$@
.PHONY
:
test
.PHONY
:
test
test
:
clean-build clean-workhorse all
test
:
clean-build clean-workhorse all
go
fmt
${PKG}
/... |
awk
'{ print } END { if (NR > 0) { print "Please run go fmt"; exit 1 } }'
go
fmt
${PKG}
/... |
awk
'{ print } END { if (NR > 0) { print "Please run go fmt"; exit 1 } }'
_support/path
go
test
${PKG}
/...
go
test
${PKG}
/...
@
echo
SUCCESS
@
echo
SUCCESS
coverage
:
coverage
:
...
@@ -44,8 +45,8 @@ clean: clean-workhorse clean-build
...
@@ -44,8 +45,8 @@ clean: clean-workhorse clean-build
.PHONY
:
clean-workhorse
.PHONY
:
clean-workhorse
clean-workhorse
:
clean-workhorse
:
rm
-f
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
cd
${BUILD_DIR}
&&
rm
-f
gitlab-workhorse gitlab-zip-cat gitlab-zip-metadata
.PHONY
:
clean-build
.PHONY
:
clean-build
clean-build
:
clean-build
:
rm
-rf
_build
rm
-rf
${BUILD_DIR}
/
_build
_support/path
deleted
100755 → 0
View file @
4d86b01f
#!/bin/sh
exec env
PATH
=
$(
pwd
)
:
${
PATH
}
"
$@
"
internal/artifacts/artifacts_test.go
0 → 100644
View file @
75ba7ebe
package
artifacts
import
(
"log"
"os"
"testing"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
)
func
TestMain
(
m
*
testing
.
M
)
{
cleanup
,
err
:=
testhelper
.
BuildExecutables
()
if
err
!=
nil
{
log
.
Printf
(
"Test setup: failed to build executables: %v"
,
err
)
os
.
Exit
(
1
)
}
os
.
Exit
(
func
()
int
{
defer
cleanup
()
return
m
.
Run
()
}())
}
internal/testhelper/testhelper.go
View file @
75ba7ebe
package
testhelper
package
testhelper
import
(
import
(
"errors"
"fmt"
"io/ioutil"
"log"
"log"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"os"
"os/exec"
"path"
"regexp"
"regexp"
"runtime"
"testing"
"testing"
)
)
var
executables
=
[]
string
{
"gitlab-workhorse"
,
"gitlab-zip-cat"
,
"gitlab-zip-metadata"
,
}
func
AssertResponseCode
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedCode
int
)
{
func
AssertResponseCode
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedCode
int
)
{
if
response
.
Code
!=
expectedCode
{
if
response
.
Code
!=
expectedCode
{
t
.
Fatalf
(
"for HTTP request expected to get %d, got %d instead"
,
expectedCode
,
response
.
Code
)
t
.
Fatalf
(
"for HTTP request expected to get %d, got %d instead"
,
expectedCode
,
response
.
Code
)
...
@@ -43,3 +56,67 @@ func TestServerWithHandler(url *regexp.Regexp, handler http.HandlerFunc) *httpte
...
@@ -43,3 +56,67 @@ func TestServerWithHandler(url *regexp.Regexp, handler http.HandlerFunc) *httpte
handler
(
w
,
r
)
handler
(
w
,
r
)
}))
}))
}
}
func
BuildExecutables
()
(
func
(),
error
)
{
_
,
currentFile
,
_
,
ok
:=
runtime
.
Caller
(
0
)
if
!
ok
{
return
nil
,
errors
.
New
(
"BuildExecutables: calling runtime.Caller failed"
)
}
rootDir
:=
path
.
Join
(
path
.
Dir
(
currentFile
),
"../.."
)
// This method will be invoked more than once due to Go test
// parallelization. We must use a unique temp directory for each
// invokation so that they do not trample each other's builds.
testDir
,
err
:=
ioutil
.
TempDir
(
""
,
"gitlab-workhorse-test"
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"could not create temp directory"
)
}
for
_
,
executable
:=
range
executables
{
utilPath
:=
path
.
Join
(
testDir
,
executable
)
if
err
:=
os
.
Remove
(
utilPath
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
nil
,
fmt
.
Errorf
(
"failed to remove: %v"
,
utilPath
)
}
}
makeCmd
:=
exec
.
Command
(
"make"
,
"BUILD_DIR="
+
testDir
)
makeCmd
.
Dir
=
rootDir
makeCmd
.
Stderr
=
os
.
Stderr
makeCmd
.
Stdout
=
os
.
Stdout
if
err
:=
makeCmd
.
Run
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to run %v in %v"
,
makeCmd
,
rootDir
)
}
for
_
,
executable
:=
range
executables
{
utilPath
:=
path
.
Join
(
testDir
,
executable
)
if
_
,
err
:=
os
.
Stat
(
utilPath
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not stat %v"
,
utilPath
)
}
}
// Try to ensure the list of executables is complete by asking "make" to only build files in the list.
cleanArgs
:=
append
([]
string
{
"clean-workhorse"
},
executables
...
)
cleanArgs
=
append
(
cleanArgs
,
"BUILD_DIR="
+
testDir
)
makeCmd
=
exec
.
Command
(
"make"
,
cleanArgs
...
)
makeCmd
.
Dir
=
rootDir
makeCmd
.
Stderr
=
os
.
Stderr
makeCmd
.
Stdout
=
os
.
Stdout
if
err
:=
makeCmd
.
Run
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to run %v in %v"
,
makeCmd
,
rootDir
)
}
oldPath
:=
os
.
Getenv
(
"PATH"
)
testPath
:=
fmt
.
Sprintf
(
"%s:%s"
,
testDir
,
oldPath
)
for
_
,
setting
:=
range
[]
struct
{
key
,
value
string
}{
{
"PATH"
,
testPath
},
}
{
if
err
:=
os
.
Setenv
(
setting
.
key
,
setting
.
value
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to set %v to %v"
,
setting
.
key
,
setting
.
value
)
}
}
return
func
()
{
os
.
Setenv
(
"PATH"
,
oldPath
)
os
.
RemoveAll
(
testDir
)
},
nil
}
main_test.go
View file @
75ba7ebe
...
@@ -43,11 +43,21 @@ func TestMain(m *testing.M) {
...
@@ -43,11 +43,21 @@ func TestMain(m *testing.M) {
testCmd
.
Stderr
=
os
.
Stderr
testCmd
.
Stderr
=
os
.
Stderr
if
err
:=
testCmd
.
Run
();
err
!=
nil
{
if
err
:=
testCmd
.
Run
();
err
!=
nil
{
log
.
Printf
(
"Test setup: failed to run %v"
,
testCmd
)
os
.
Exit
(
-
1
)
os
.
Exit
(
-
1
)
}
}
}
}
os
.
Exit
(
m
.
Run
())
cleanup
,
err
:=
testhelper
.
BuildExecutables
()
if
err
!=
nil
{
log
.
Printf
(
"Test setup: failed to build executables: %v"
,
err
)
os
.
Exit
(
1
)
}
os
.
Exit
(
func
()
int
{
defer
cleanup
()
return
m
.
Run
()
}())
}
}
func
TestAllowedClone
(
t
*
testing
.
T
)
{
func
TestAllowedClone
(
t
*
testing
.
T
)
{
...
...
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