This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from jcvenegas/cli-runtime
cli: Initial runtime cli implementation.
- Loading branch information
Showing
797 changed files
with
20,510 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
go_packages=. | ||
|
||
candidates=`go list -f '{{.Dir}}/*.go' $go_packages` | ||
for f in $candidates; do | ||
filename=`basename $f` | ||
# skip exit.go where, the only file we should call os.Exit() from. | ||
[[ $filename == "exit.go" ]] && continue | ||
# skip exit_test.go | ||
[[ $filename == "exit_test.go" ]] && continue | ||
# skip main_test.go | ||
[[ $filename == "main_test.go" ]] && continue | ||
files="$f $files" | ||
done | ||
|
||
if egrep -n '\<os\.Exit\>' $files; then | ||
echo "Direct calls to os.Exit() are forbidden, please use exit() so atexit() works" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
# Perform static go tests. | ||
|
||
function usage { | ||
echo "Usage $0 [OPTIONS] [PACKAGES]" | ||
echo "Perform static go checks on PACKAGES (./... by default)." | ||
echo | ||
echo "List of options:" | ||
echo " -h, --help print this help" | ||
echo " -n, --no-network do not access the network" | ||
} | ||
|
||
for i in "$@"; do | ||
case $i in | ||
-h|--help) | ||
usage | ||
exit 0 | ||
;; | ||
-n|--no-network) | ||
NONETWORK=1 | ||
shift | ||
;; | ||
*) | ||
args="$args $i" | ||
;; | ||
esac | ||
done | ||
|
||
go_packages=$args | ||
|
||
[ -z "$go_packages" ] && { | ||
go_packages=$(go list ./... | grep -v vendor) | ||
} | ||
|
||
function install_package { | ||
url="$1" | ||
name=${url##*/} | ||
|
||
if [ -n "$NONETWORK" ]; then | ||
echo "Skipping updating package $name, no network access allowed" | ||
return | ||
fi | ||
|
||
echo Updating $name... | ||
go get -u $url | ||
} | ||
|
||
install_package github.com/fzipp/gocyclo | ||
install_package github.com/client9/misspell/cmd/misspell | ||
install_package github.com/golang/lint/golint | ||
install_package github.com/gordonklaus/ineffassign | ||
install_package github.com/opennota/check/cmd/structcheck | ||
install_package honnef.co/go/tools/cmd/unused | ||
install_package honnef.co/go/tools/cmd/staticcheck | ||
|
||
echo Doing go static checks on packages: $go_packages | ||
|
||
echo "Running misspell..." | ||
go list -f '{{.Dir}}/*.go' $go_packages |\ | ||
xargs -I % bash -c "misspell -error %" | ||
|
||
echo "Running go vet..." | ||
go vet $go_packages | ||
|
||
cmd="gofmt -s -d -l" | ||
echo "Running gofmt..." | ||
|
||
# Note: ignore git directory in case any refs end in ".go" too. | ||
diff=$(find . -not -wholename '*/vendor/*' -not -wholename '*/.git/*' -name '*.go' | \ | ||
xargs $cmd) | ||
if [ -n "$diff" -a $(echo "$diff" | wc -l) -ne 0 ] | ||
then | ||
echo 2>&1 "ERROR: '$cmd' found problems:" | ||
echo 2>&1 "$diff" | ||
exit 1 | ||
fi | ||
|
||
echo "Running cyclo..." | ||
gocyclo -over 15 `go list -f '{{.Dir}}/*.go' $go_packages` | ||
|
||
echo "Running golint..." | ||
for p in $go_packages; do golint -set_exit_status $p; done | ||
|
||
echo "Running ineffassign..." | ||
go list -f '{{.Dir}}' $go_packages | xargs -L 1 ineffassign | ||
|
||
for tool in structcheck unused staticcheck | ||
do | ||
echo "Running ${tool}..." | ||
eval "$tool" "$go_packages" | ||
done | ||
|
||
echo "All Good!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
script_dir=$(cd `dirname $0`; pwd) | ||
root_dir=`dirname $script_dir` | ||
|
||
test_packages="." | ||
|
||
# Set default test run timeout value. | ||
# | ||
# CC_GO_TEST_TIMEOUT can be set to any value accepted by | ||
# "go test -timeout X" | ||
timeout_value=${CC_GO_TEST_TIMEOUT:-10s} | ||
|
||
go_test_flags="-v -race -timeout $timeout_value" | ||
cov_file="profile.cov" | ||
tmp_cov_file="profile_tmp.cov" | ||
|
||
# Run a command as either root or the current user (which might still be root). | ||
# | ||
# If the first argument is "root", run using sudo, else run as normal. | ||
# All arguments after the first will be treated as the command to run. | ||
function run_as_user | ||
{ | ||
user="$1" | ||
shift | ||
cmd=$* | ||
|
||
if [ "$user" = root ] | ||
then | ||
# use a shell to ensure PATH is correct. | ||
sudo -E PATH="$PATH" sh -c "$cmd" | ||
else | ||
$cmd | ||
fi | ||
} | ||
|
||
function test_html_coverage | ||
{ | ||
html_report="coverage.html" | ||
|
||
test_coverage | ||
|
||
go tool cover -html="${cov_file}" -o "${html_report}" | ||
rm -f "${cov_file}" | ||
|
||
run_as_user "current" chmod 644 "${html_report}" | ||
} | ||
|
||
function test_coverage | ||
{ | ||
echo "mode: atomic" > "$cov_file" | ||
|
||
if [ $(id -u) -eq 0 ] | ||
then | ||
echo >&2 "WARNING: Already running as root so will not re-run tests as non-root user." | ||
echo >&2 "WARNING: As a result, only a subset of tests will be run" | ||
echo >&2 "WARNING: (run this script as a non-privileged to ensure all tests are run)." | ||
users="current" | ||
else | ||
# Run the unit-tests *twice* (since some must run as root and | ||
# others must run as non-root), combining the resulting test | ||
# coverage files. | ||
users="current root" | ||
fi | ||
|
||
for pkg in $test_packages; do | ||
for user in $users; do | ||
printf "INFO: Running 'go test' as %s user on packages '%s' with flags '%s'\n" "$user" "$test_packages" "$go_test_flags" | ||
|
||
run_as_user "$user" go test $go_test_flags -covermode=atomic -coverprofile="$tmp_cov_file" $pkg | ||
if [ -f "${tmp_cov_file}" ]; then | ||
run_as_user "$user" chmod 644 "$tmp_cov_file" | ||
tail -n +2 "$tmp_cov_file" >> "$cov_file" | ||
run_as_user "$user" rm -f "$tmp_cov_file" | ||
fi | ||
done | ||
done | ||
} | ||
|
||
function test_local | ||
{ | ||
go test $go_test_flags $test_packages | ||
} | ||
|
||
if [ "$1" = "html-coverage" ]; then | ||
test_html_coverage | ||
elif [ "$CI" = "true" ]; then | ||
test_coverage | ||
else | ||
test_local | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.