Skip to content

Commit

Permalink
goclean: add vendor check; add '-i' flag
Browse files Browse the repository at this point in the history
Add check that vendor directory is installed and if not we should run
glide install, also if additional flag '-i' is specified than we will
reinstall dependencies.
  • Loading branch information
andrewshvv authored and Roasbeef committed Mar 15, 2017
1 parent e4e63eb commit d723aad
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions gotest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ check_test_ports() {
# coverage profile. Be aware that we are skipping the integration tests, as the
# tool won't gather any useful coverage information from them.
test_with_coverage_profile() {
print "* Run tests with creating coverage profile:"
print "* Run tests with creating coverage profile"
check_test_ports

echo "mode: count" > profile.cov
Expand All @@ -58,7 +58,7 @@ test_with_coverage_profile() {
done

if [ "$TRAVIS" == "true" ] ; then
print "* Send test coverage to travis server:"
print "* Send test coverage to travis server"
# Make sure goveralls is installed and $GOPATH/bin is in your path.
if [ ! -x "$(type -p goveralls)" ]; then
print "** Install goveralls:"
Expand All @@ -73,7 +73,7 @@ test_with_coverage_profile() {
# test_race_conditions run standard go test without creating coverage
# profile but with race condition checks.
test_race_conditions() {
print "* Run tests with race conditions checks:"
print "* Run tests with race conditions checks"
check_test_ports

test_targets=$(go list ./... | grep -v '/vendor/')
Expand All @@ -82,11 +82,11 @@ test_race_conditions() {

# lint_check runs static checks.
lint_check() {
print "* Run static checks:"
print "* Run static checks"

# Make sure gometalinter is installed and $GOPATH/bin is in your path.
if [ ! -x "$(type -p gometalinter)" ]; then
print "** Install gometalinter:"
print "** Install gometalinter"
go get -v github.com/alecthomas/gometalinter
gometalinter --install
fi
Expand All @@ -105,21 +105,26 @@ lint_check() {

set -e

print "====+ Start +===="

# Read input flags and initialize variables
NEED_LINT="false"
NEED_COVERAGE="false"
NEED_RACE="false"
NEED_INSTALL="false"

while getopts "lrc" flag; do
while getopts "lrci" flag; do
case "${flag}" in
l) NEED_LINT="true" ;;
r) NEED_RACE="true" ;;
c) NEED_COVERAGE="true" ;;
i) NEED_INSTALL="true" ;;
*)
printf '\nUsage: %s [-l] [-r] [-c], where:\n' $0
printf '\nUsage: %s [-l] [-r] [-c] [-i], where:\n' $0
printf ' -l: include code lint check\n'
printf ' -r: run tests with race condition check\n'
printf ' -c: run tests with test coverage\n'
printf ' -i: reinstall project dependencies\n'
exit 1 ;;
esac
done
Expand All @@ -129,13 +134,19 @@ shift $(( OPTIND - 1 ))

# Make sure glide is installed and $GOPATH/bin is in your path.
if [ ! -x "$(type -p glide)" ]; then
print "* Install glide:"
print "* Install glide"
go get -u github.com/Masterminds/glide
fi

# Install the dependency if vendor directory not exist or if flag have been
# specified.
if [ "$NEED_INSTALL" == "true" ] || [ ! -d "./vendor" ]; then
print "* Install dependencies"
glide install
fi

# Required for the integration tests
print "* Build source:"
print "* Build source"
go install -v . ./cmd/...

# Lint check is first because we shouldn't run tests on garbage code.
Expand All @@ -152,4 +163,6 @@ fi
# we may calmly send coverage profile (if script is run on travis)
if [ "$NEED_COVERAGE" == "true" ]; then
test_with_coverage_profile
fi
fi

print "=====+ End +====="

0 comments on commit d723aad

Please sign in to comment.