Skip to content

Commit

Permalink
Merge pull request #10 from jancajthaml-openbank/feature/collect-test…
Browse files Browse the repository at this point in the history
…-coverage

collect test coverage
  • Loading branch information
jancajthaml authored Jul 1, 2019
2 parents 357bcbd + b168686 commit 10de2d8
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 50 deletions.
9 changes: 9 additions & 0 deletions .depignore
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
reports
*.test
17 changes: 14 additions & 3 deletions Makefile
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
53 changes: 53 additions & 0 deletions dev/lifecycle/lint
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
33 changes: 33 additions & 0 deletions dev/lifecycle/sec
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 ./...
48 changes: 48 additions & 0 deletions dev/lifecycle/sync
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
65 changes: 65 additions & 0 deletions dev/lifecycle/test
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
53 changes: 53 additions & 0 deletions docker-compose.yml
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"]

# ---------------------------------------------------------------------------- #
Loading

0 comments on commit 10de2d8

Please sign in to comment.