Skip to content

Commit 10de2d8

Browse files
authored
Merge pull request #10 from jancajthaml-openbank/feature/collect-test-coverage
collect test coverage
2 parents 357bcbd + b168686 commit 10de2d8

File tree

10 files changed

+306
-50
lines changed

10 files changed

+306
-50
lines changed

.depignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
vendor
3+
dev
4+
reports
5+
.gitignore
6+
.editorconfig
7+
.env
8+
.depignore
9+
docker-compose.yml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
reports
3+
*.test

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
.ONESHELL:
22

33
.PHONY: all
4-
all: test
4+
all: sync test lint sec
5+
6+
.PHONY: lint
7+
lint:
8+
@docker-compose run --rm lint --pkg local-fs || :
9+
10+
.PHONY: sec
11+
sec:
12+
@docker-compose run --rm sec --pkg local-fs || :
13+
14+
.PHONY: sync
15+
sync:
16+
@docker-compose run --rm sync --pkg local-fs
517

618
.PHONY: test
719
test:
8-
GOMAXPROCS=1 \
9-
go test -v ./... -benchmem -bench=. -timeout=20s
20+
@docker-compose run --rm test --pkg local-fs

dev/lifecycle/lint

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
trap exit INT TERM
5+
6+
TARGET_PACKAGE=""
7+
8+
while [ $# -gt 0 ] ; do
9+
key="$1"
10+
11+
case $key in
12+
13+
--pkg)
14+
TARGET_PACKAGE="$2"
15+
shift
16+
shift
17+
;;
18+
19+
*)
20+
shift
21+
;;
22+
23+
esac
24+
done
25+
26+
if [ ! "${TARGET_PACKAGE}" ] ; then
27+
(>&2 echo "[error] target package not provided")
28+
exit 1
29+
fi
30+
31+
scan() {
32+
if [ ! -f ${1} ] ; then
33+
return
34+
fi
35+
(gofmt -s -w ${1} || :)
36+
(/go/bin/golint -min_confidence 0.5 ${1} || :)
37+
(/go/bin/misspell ${1} || :)
38+
(/go/bin/prealloc ${1} || :)
39+
(/go/bin/gocyclo -over 15 ${1} || :)
40+
(/go/bin/prealloc ${1} || :)
41+
(/go/bin/goconst ${1} || :)
42+
(/go/bin/ineffassign ${1} || :)
43+
}
44+
45+
find /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE} \
46+
-name "*.go" \
47+
-not \
48+
-path "*vendor/*" \
49+
\
50+
| sort -u \
51+
| while read f ; do
52+
scan ${f}
53+
done

dev/lifecycle/sec

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
trap exit INT TERM
5+
6+
TARGET_PACKAGE=""
7+
8+
while [ $# -gt 0 ] ; do
9+
key="$1"
10+
11+
case $key in
12+
13+
--pkg)
14+
TARGET_PACKAGE="$2"
15+
shift
16+
shift
17+
;;
18+
19+
*)
20+
shift
21+
;;
22+
23+
esac
24+
done
25+
26+
if [ ! "${TARGET_PACKAGE}" ] ; then
27+
(>&2 echo "[error] target package not provided")
28+
exit 1
29+
fi
30+
31+
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE}
32+
33+
gosec ./...

dev/lifecycle/sync

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
trap exit INT TERM
5+
6+
TARGET_PACKAGE=""
7+
8+
while [ $# -gt 0 ] ; do
9+
key="$1"
10+
11+
case $key in
12+
13+
--pkg)
14+
TARGET_PACKAGE="$2"
15+
shift
16+
shift
17+
;;
18+
19+
*)
20+
shift
21+
;;
22+
23+
esac
24+
done
25+
26+
if [ ! "${TARGET_PACKAGE}" ] ; then
27+
(>&2 echo "[error] target package not provided")
28+
exit 1
29+
fi
30+
31+
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE}
32+
33+
if [ -d vendor ] ; then
34+
rm -rf vendor
35+
fi
36+
37+
if [ -f go.sum ] ; then
38+
rm -f go.sum
39+
fi
40+
41+
GO111MODULE=on \
42+
go mod verify
43+
44+
GO111MODULE=on \
45+
go mod tidy
46+
47+
GO111MODULE=on \
48+
go mod vendor

dev/lifecycle/test

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
set -e
4+
trap exit INT TERM
5+
6+
TARGET_PACKAGE=""
7+
8+
while [ $# -gt 0 ] ; do
9+
key="$1"
10+
11+
case $key in
12+
13+
--pkg)
14+
TARGET_PACKAGE="$2"
15+
shift
16+
shift
17+
;;
18+
19+
*)
20+
shift
21+
;;
22+
23+
esac
24+
done
25+
26+
if [ ! "${TARGET_PACKAGE}" ] ; then
27+
(>&2 echo "[error] target package not provided")
28+
exit 1
29+
fi
30+
31+
coverage_out=$(tempfile)
32+
test_out=$(tempfile)
33+
reports_out=$(pwd)/reports
34+
35+
mkdir -p ${reports_out} ${reports_out}/unit-tests-${TARGET_PACKAGE}
36+
37+
cd /go/src/github.com/jancajthaml-openbank/${TARGET_PACKAGE}
38+
39+
# run unit tests and collect coverage
40+
41+
2>&1 \
42+
go test \
43+
-v ./... \
44+
-coverprofile=${coverage_out} \
45+
-coverpkg=./... \
46+
-timeout=20s | tee ${test_out}
47+
48+
go2xunit \
49+
-fail \
50+
-input ${test_out} \
51+
-output ${reports_out}/unit-tests-${TARGET_PACKAGE}/results.xml
52+
53+
go tool cover \
54+
--html=${coverage_out} \
55+
-o ${reports_out}/unit-tests-${TARGET_PACKAGE}/coverage.html
56+
57+
# run only benchmarks
58+
59+
GOMAXPROCS=1 \
60+
go test \
61+
-v ./... \
62+
-run=^$ \
63+
-bench=. \
64+
-benchmem \
65+
-timeout=1m

docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: '2'
2+
3+
# ---------------------------------------------------------------------------- #
4+
5+
services:
6+
7+
# -------------------------------------------------------------------------- #
8+
9+
go:
10+
image: jancajthaml/go
11+
volumes:
12+
- .:/project
13+
- .:/go/src/github.com/jancajthaml-openbank/local-fs
14+
working_dir: /go/src/github.com/jancajthaml-openbank/local-fs
15+
environment:
16+
- GOOS
17+
- GOARCH
18+
- GOPATH=/go
19+
- COMPOSE_PROJECT_NAME
20+
entrypoint: ["go"]
21+
privileged: true
22+
23+
# -------------------------------------------------------------------------- #
24+
25+
sync:
26+
extends: go
27+
entrypoint: ["/project/dev/lifecycle/sync"]
28+
29+
# -------------------------------------------------------------------------- #
30+
31+
update:
32+
extends: go
33+
entrypoint: ["/project/dev/lifecycle/update"]
34+
35+
# -------------------------------------------------------------------------- #
36+
37+
lint:
38+
extends: go
39+
entrypoint: ["/project/dev/lifecycle/lint"]
40+
41+
# -------------------------------------------------------------------------- #
42+
43+
sec:
44+
extends: go
45+
entrypoint: ["/project/dev/lifecycle/sec"]
46+
47+
# -------------------------------------------------------------------------- #
48+
49+
test:
50+
extends: go
51+
entrypoint: ["/project/dev/lifecycle/test"]
52+
53+
# ---------------------------------------------------------------------------- #

0 commit comments

Comments
 (0)