Skip to content

Commit

Permalink
Merge pull request #12 from regen-network/9-setup-test-coverage-CI-job
Browse files Browse the repository at this point in the history
[#9] add codecov coverage reporting
  • Loading branch information
aaronc authored Mar 26, 2019
2 parents 52f76f6 + f31642e commit 8e5cbef
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# This codecov.yml is the default configuration for
# all repositories on Codecov. You may adjust the settings
# below in your own codecov.yml in your repository.
#
coverage:
precision: 2
round: down
range: 70...100

status:
# Learn more at https://codecov.io/docs#yaml_default_commit_status
project:
default:
threshold: 1% # allow this much decrease on project
changes: false

comment:
layout: "header, diff"
behavior: default # update if exists else create new

ignore:
- "docs"
- "*.md"
- "*.org"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ flycheck_*.el

# Test binary, build with `go test -c`
*.test
coverage.txt

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
7 changes: 3 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ test:
image: golang:1.11.5
script:
- GOFLAGS=-cover make test
coverage: '/\d+.\d+% of statements/'
artifacts:
reports:
junit: "TEST_*.xml"
after_script:
- make test_cover
- bash <(curl -s https://codecov.io/bash) -f coverage.txt -t $CODECOV_TOKEN

#integration_test:
# image: golang:1.11.5
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ install:
test:
go test ./... -godog.strict

test_cover:
bash -x tests/test_cover.sh

lint:
go get -u golang.org/x/lint/golint
${GOPATH}/bin/golint -set_exit_status ./...
14 changes: 14 additions & 0 deletions tests/test_cover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

PKGS=$(go list ./...)

set -e
echo "mode: atomic" > coverage.txt
for pkg in ${PKGS[@]}; do
go test -v -timeout 30m -race -coverprofile=profile.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg"
if [ -f profile.out ]; then
tail -n +2 profile.out >> coverage.txt;
rm profile.out
fi
done
44 changes: 44 additions & 0 deletions x/esp/esp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package esp

import (
"github.com/DATA-DOG/godog"
"github.com/DATA-DOG/godog/gherkin"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/regen-network/regen-ledger/util"
abci "github.com/tendermint/tendermint/abci/types"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"testing"
)

var cdc *codec.Codec
var ctx sdk.Context
//var keeper Keeper

func setupTestInput() {
db := dbm.NewMemDB()

cdc = codec.New()

espKey := sdk.NewKVStoreKey("espKey")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(espKey, sdk.StoreTypeIAVL, db)
_ = ms.LoadLatestVersion()

//keeper = NewKeeper(espKey, agentKeeper, geoKeeper, cdc)
ctx = sdk.NewContext(ms, abci.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger())
}

func TestMain(m *testing.M) {
util.GodogMain(m, "esp", FeatureContext)
}

func FeatureContext(s *godog.Suite) {
s.BeforeFeature(func(*gherkin.Feature) {
setupTestInput()
})
}

0 comments on commit 8e5cbef

Please sign in to comment.