-
Notifications
You must be signed in to change notification settings - Fork 1
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 #10 from jancajthaml-openbank/feature/collect-test…
…-coverage collect test coverage
- Loading branch information
Showing
10 changed files
with
306 additions
and
50 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,9 @@ | ||
.git | ||
vendor | ||
dev | ||
reports | ||
.gitignore | ||
.editorconfig | ||
.env | ||
.depignore | ||
docker-compose.yml |
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,3 @@ | ||
vendor | ||
reports | ||
*.test |
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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
.ONESHELL: | ||
|
||
.PHONY: all | ||
all: test | ||
all: sync test lint sec | ||
|
||
.PHONY: lint | ||
lint: | ||
@docker-compose run --rm lint --pkg local-fs || : | ||
|
||
.PHONY: sec | ||
sec: | ||
@docker-compose run --rm sec --pkg local-fs || : | ||
|
||
.PHONY: sync | ||
sync: | ||
@docker-compose run --rm sync --pkg local-fs | ||
|
||
.PHONY: test | ||
test: | ||
GOMAXPROCS=1 \ | ||
go test -v ./... -benchmem -bench=. -timeout=20s | ||
@docker-compose run --rm test --pkg local-fs |
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,53 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
trap exit INT TERM | ||
|
||
TARGET_PACKAGE="" | ||
|
||
while [ $# -gt 0 ] ; do | ||
key="$1" | ||
|
||
case $key in | ||
|
||
--pkg) | ||
TARGET_PACKAGE="$2" | ||
shift | ||
shift | ||
;; | ||
|
||
*) | ||
shift | ||
;; | ||
|
||
esac | ||
done | ||
|
||
if [ ! "${TARGET_PACKAGE}" ] ; then | ||
(>&2 echo "[error] target package not provided") | ||
exit 1 | ||
fi | ||
|
||
scan() { | ||
if [ ! -f ${1} ] ; then | ||
return | ||
fi | ||
(gofmt -s -w ${1} || :) | ||
(/go/bin/golint -min_confidence 0.5 ${1} || :) | ||
(/go/bin/misspell ${1} || :) | ||
(/go/bin/prealloc ${1} || :) | ||
(/go/bin/gocyclo -over 15 ${1} || :) | ||
(/go/bin/prealloc ${1} || :) | ||
(/go/bin/goconst ${1} || :) | ||
(/go/bin/ineffassign ${1} || :) | ||
} | ||
|
||
find /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE} \ | ||
-name "*.go" \ | ||
-not \ | ||
-path "*vendor/*" \ | ||
\ | ||
| sort -u \ | ||
| while read f ; do | ||
scan ${f} | ||
done |
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,33 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
trap exit INT TERM | ||
|
||
TARGET_PACKAGE="" | ||
|
||
while [ $# -gt 0 ] ; do | ||
key="$1" | ||
|
||
case $key in | ||
|
||
--pkg) | ||
TARGET_PACKAGE="$2" | ||
shift | ||
shift | ||
;; | ||
|
||
*) | ||
shift | ||
;; | ||
|
||
esac | ||
done | ||
|
||
if [ ! "${TARGET_PACKAGE}" ] ; then | ||
(>&2 echo "[error] target package not provided") | ||
exit 1 | ||
fi | ||
|
||
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE} | ||
|
||
gosec ./... |
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,48 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
trap exit INT TERM | ||
|
||
TARGET_PACKAGE="" | ||
|
||
while [ $# -gt 0 ] ; do | ||
key="$1" | ||
|
||
case $key in | ||
|
||
--pkg) | ||
TARGET_PACKAGE="$2" | ||
shift | ||
shift | ||
;; | ||
|
||
*) | ||
shift | ||
;; | ||
|
||
esac | ||
done | ||
|
||
if [ ! "${TARGET_PACKAGE}" ] ; then | ||
(>&2 echo "[error] target package not provided") | ||
exit 1 | ||
fi | ||
|
||
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE} | ||
|
||
if [ -d vendor ] ; then | ||
rm -rf vendor | ||
fi | ||
|
||
if [ -f go.sum ] ; then | ||
rm -f go.sum | ||
fi | ||
|
||
GO111MODULE=on \ | ||
go mod verify | ||
|
||
GO111MODULE=on \ | ||
go mod tidy | ||
|
||
GO111MODULE=on \ | ||
go mod vendor |
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,65 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
trap exit INT TERM | ||
|
||
TARGET_PACKAGE="" | ||
|
||
while [ $# -gt 0 ] ; do | ||
key="$1" | ||
|
||
case $key in | ||
|
||
--pkg) | ||
TARGET_PACKAGE="$2" | ||
shift | ||
shift | ||
;; | ||
|
||
*) | ||
shift | ||
;; | ||
|
||
esac | ||
done | ||
|
||
if [ ! "${TARGET_PACKAGE}" ] ; then | ||
(>&2 echo "[error] target package not provided") | ||
exit 1 | ||
fi | ||
|
||
coverage_out=$(tempfile) | ||
test_out=$(tempfile) | ||
reports_out=$(pwd)/reports | ||
|
||
mkdir -p ${reports_out} ${reports_out}/unit-tests-${TARGET_PACKAGE} | ||
|
||
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE} | ||
|
||
# run unit tests and collect coverage | ||
|
||
2>&1 \ | ||
go test \ | ||
-v ./... \ | ||
-coverprofile=${coverage_out} \ | ||
-coverpkg=./... \ | ||
-timeout=20s | tee ${test_out} | ||
|
||
go2xunit \ | ||
-fail \ | ||
-input ${test_out} \ | ||
-output ${reports_out}/unit-tests-${TARGET_PACKAGE}/results.xml | ||
|
||
go tool cover \ | ||
--html=${coverage_out} \ | ||
-o ${reports_out}/unit-tests-${TARGET_PACKAGE}/coverage.html | ||
|
||
# run only benchmarks | ||
|
||
GOMAXPROCS=1 \ | ||
go test \ | ||
-v ./... \ | ||
-run=^$ \ | ||
-bench=. \ | ||
-benchmem \ | ||
-timeout=1m |
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,53 @@ | ||
version: '2' | ||
|
||
# ---------------------------------------------------------------------------- # | ||
|
||
services: | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
go: | ||
image: jancajthaml/go | ||
volumes: | ||
- .:/project | ||
- .:/go/src/github.com/jancajthaml-openbank/local-fs | ||
working_dir: /go/src/github.com/jancajthaml-openbank/local-fs | ||
environment: | ||
- GOOS | ||
- GOARCH | ||
- GOPATH=/go | ||
- COMPOSE_PROJECT_NAME | ||
entrypoint: ["go"] | ||
privileged: true | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
sync: | ||
extends: go | ||
entrypoint: ["/project/dev/lifecycle/sync"] | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
update: | ||
extends: go | ||
entrypoint: ["/project/dev/lifecycle/update"] | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
lint: | ||
extends: go | ||
entrypoint: ["/project/dev/lifecycle/lint"] | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
sec: | ||
extends: go | ||
entrypoint: ["/project/dev/lifecycle/sec"] | ||
|
||
# -------------------------------------------------------------------------- # | ||
|
||
test: | ||
extends: go | ||
entrypoint: ["/project/dev/lifecycle/test"] | ||
|
||
# ---------------------------------------------------------------------------- # |
Oops, something went wrong.