1#!/bin/bash
2
3echo "mode: count" > acc.out
4for Dir in . $(find ./* -maxdepth 10 -type d | grep -v vendor);
5do
6	if ls $Dir/*.go &> /dev/null;
7	then
8		returnval=`go test -coverprofile=profile.out -covermode=count $Dir`
9		echo ${returnval}
10		if [[ ${returnval} != *FAIL* ]]
11		then
12    		if [ -f profile.out ]
13    		then
14        		cat profile.out | grep -v "mode: count" >> acc.out
15    		fi
16    	else
17    		exit 1
18    	fi
19    fi
20done
21
22# collect integration test coverage
23echo "mode: count" > integration-acc.out
24INTPACKS=`go list ./... | grep -v vendor | grep -v utils | grep -v 'store/test' | grep -v docs | xargs | sed 's/ /,/g'`
25returnval=`go test -coverpkg=$INTPACKS -coverprofile=profile.out -covermode=count ./test`
26if [[ ${returnval} != *FAIL* ]]
27then
28    if [ -f profile.out ]
29    then
30        cat profile.out | grep -v "mode: count" >> integration-acc.out
31    fi
32else
33    exit 1
34fi
35
36cat acc.out integration-acc.out | go run docs/merge-coverprofile.go > merged.out
37
38if [ -n "$COVERALLS" ]
39then
40    export GIT_BRANCH=$TRAVIS_BRANCH
41	goveralls -service drone.io -coverprofile=merged.out -repotoken $COVERALLS
42fi
43
44if [ -n "$COVERHTML" ]
45then
46    go tool cover -html=merged.out
47fi
48
49rm -rf ./profile.out
50rm -rf ./acc.out
51rm -rf ./integration-acc.out
52rm -rf ./merged.out
53