1build icon indicating copy to clipboard operation
1build copied to clipboard

Add Code coverage to PR

Open gopinath-langote opened this issue 5 years ago • 9 comments

  • Codecov https://codecov.io

gopinath-langote avatar Aug 24 '19 19:08 gopinath-langote

@gopinath-langote I'd like to take a go ;) at this one

amitlevy21 avatar Aug 26 '19 14:08 amitlevy21

@amitlevy21 Thanks for picking up.

Let me know if you need any access things for Codecov https://codecov.io.

gopinath-langote avatar Aug 26 '19 14:08 gopinath-langote

@gopinath-langote I am testing on a fork, codecov complains that the coverage file is empty. Running the following command: go test -cover -race --coverprofile=coverage.txt -covermode=atomic ./testing -run . Yields the following: ok github.com/gopinath-langote/1build/testing 1.713s coverage: 0.0% of statements I only found cli_test.go to be the only file with tests, am I correct? how come it says 0.0% is covered?

Output of coverage.txt: mode: atomic

amitlevy21 avatar Aug 27 '19 17:08 amitlevy21

The test PR I made on my fork: https://github.com/amitlevy21/1build/pull/1 (has CI logs) The codecov page: https://codecov.io/gh/amitlevy21/1build/commit/6c9f68a8f55aaadc40010ff7b9296118bb20cf41

amitlevy21 avatar Aug 27 '19 17:08 amitlevy21

I only found cli_test.go to be the only file with tests

Yes, That is the only file with test - other files are fixtures to create test data

gopinath-langote avatar Aug 27 '19 18:08 gopinath-langote

There are integration tests not unit tests.

So It might not be trivial to get coverage,

Checkout https://www.cyphar.com/blog/post/20170412-golang-integration-coverage

gopinath-langote avatar Aug 27 '19 18:08 gopinath-langote

I found a simpler solution by using go test -v -coverpkg ./... ./... See: https://travis-ci.org/amitlevy21/1build/jobs/578187996 https://github.com/amitlevy21/1build/pull/1

Can I open a PR?

amitlevy21 avatar Aug 29 '19 05:08 amitlevy21

hello @amitlevy21 Thanks for the effort. unfortunately, the coverage is not correct. Look at codecov generated by your commit: https://codecov.io/gh/amitlevy21/1build/tree/e31f920171fc24b616f12acef34e261b89ebbe7d

I know this is not trivial to get coverage for such binary integration tests.

I'm also trying to figure out the way.

gopinath-langote avatar Aug 29 '19 07:08 gopinath-langote

@gopinath-langote So from my understanding, Were seeing the wrong coverage rate because go test doesn't recognize the use of the cli via cobra, right?

I didn't find any issue regarding this in the cobra repository, should I create one?

amitlevy21 avatar Sep 01 '19 15:09 amitlevy21