forked from RedHatInsights/insights-results-aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-coverage.sh
executable file
·74 lines (62 loc) · 2.49 KB
/
make-coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
TIMEOUT=2m
TIMEOUT_INTEGRATION=1440m
rm coverage.out 2>/dev/null
case $1 in
"unit-sqlite")
echo "Running unit tests with SQLite in memory..."
go test -timeout $TIMEOUT -coverprofile=coverage.out ./... 1>&2
;;
"unit-postgres")
export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB="postgres"
export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB_ADMIN_PASS="admin"
echo "Running unit tests with postgres..."
go test -timeout $TIMEOUT -coverprofile=coverage.out ./... 1>&2
;;
"rest")
echo rest # TODO: rest
echo "Running REST API tests..."
rm test.db 2> /dev/null
rm ./insights-results-aggregator.test 2> /dev/null
go test -timeout $TIMEOUT -c -v -tags testrunmain -coverpkg="./..." . 1>&2
# would be better to put inside a subshell, but linter doesn't like it
export INSIGHTS_RESULTS_AGGREGATOR_CONFIG_FILE=./tests/tests
(
echo "Migrating the DB"
go run . migrate latest
echo "Starting a service"
./insights-results-aggregator.test -test.v -test.run "^TestRunMain$" -test.coverprofile=coverage.out 1>&2
) &
# TODO: use curl in a loop to test when service is available
sleep 2s
./test.sh --verbose --no-service 1>&2
pkill --signal SIGINT -f insights-results-aggregator.test
rm ./insights-results-aggregator.test 2>/dev/null
;;
"integration")
echo "Running a service..."
echo "Start your integration tests and press Ctrl+C when they are done"
export INSIGHTS_RESULTS_AGGREGATOR_CONFIG_FILE=./config-devel
go test -timeout $TIMEOUT_INTEGRATION -v -tags testrunmain -run "^TestRunMain$" -coverprofile=coverage.out -coverpkg="./..." . 1>&2
;;
*)
echo 'Please, choose "unit-sqlite", "unit-postgres", "rest" or "integration"'
echo "Aggregator's output will be redirected to stderr."
echo "Coverage is saved to 'coverage.out' file"
exit 1
;;
esac
go tool cover -func=coverage.out | grep -E "^total"