How to check python test coverage against go lang code


(Prerna Manaktala) #1

Hi

I am able to generate the *.test files in the go lang code and also run the
./value.test -systemTest -test.coverprofile coverage.cov
to generate various coverage.cov files and unit.cov files separately.
But I did all this in the go lang codebase.

How can I get the coverage of golang code from my python tests using above information?


(ruflin) #2

Hi @Prerna_Manaktala

Based on your description, I assume you followed https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests The question you must answer first, what kind of additional tests do you want to to with the test binary that you need an additional language like python or an other language you feel comfortable in.

The typical tests here are system tests where the binary is tested from the "outside". So assuming you use python, you must implement your use case you want to test in python and instead of using the normal binary to execute, use the testing binary you created and add the above flag. In Python for the execution of the binary you can typically use args.* to create the command with all arguments (see here an example https://github.com/elastic/libbeat/blob/master/tests/system/mockbeat.py#L65 ).

So first think of what you would want to test be it with the normal binary or the coverage binary, and then you can add the coverage in a second step.


(Prerna Manaktala) #3

Yes I have use cases implemented already and they use the normal binary as:
pytests/tuqquery/newtuq.py: "./cbq-engine.exe -datastore http://%s:%s/ >/dev/null 2>&1 &" %(
pytests/tuqquery/newtuq.py: "./cbq-engine -datastore http://%s:%s/ >n1ql.log 2>&1 &" %(
pytests/tuqquery/newtuq.py: "./cbq-engine.exe -datastore http://%s:%s/ >/dev/null 2>&1 &" %(
pytests/tuqquery/newtuq.py: "./cbq-engine -datastore http://%s:%s/ >n1ql.log 2>&1 &" %(
pytests/tuqquery/newtuq.py: './cbq-engine -datastore http://%s:%s/ -http=":%s">n1ql.log 2>&1 &' %(
pytests/tuqquery/newtuq.py: cmd = "cd /tmp/tuq;./cbq-engine -couchbase http://%s:%s/ >/dev/null 2>&1 &" %(
pytests/tuqquery/newtuq.py: cmd = "cd /cygdrive/c/tuq;./cbq-engine.exe -couchbase http://%s:%s/ >/dev/null 2>&1 &" %(
pytests/tuqquery/tuq.py: o = self.shell.execute_command("ps -aef| grep cbq-engine")
pytests/tuqquery/tuq.py: cmd = "cd %s/src/github.com/couchbase/query/server/cbq-engine; " % (gopath) +
pytests/tuqquery/tuq.py: "./cbq-engine.exe -datastore=dir:%sdata >/dev/null 2>&1 &" % (self.directory_flat_json)
pytests/tuqquery/tuq.py: cmd = "cd %s/src/github.com/couchbase/query/server/cbq-engine; " % (gopath) +
pytests/tuqquery/tuq.py: "./cbq-engine -datastore=dir:%s/data >n1ql.log 2>&1 &" %(self.directory_flat_json)
pytests/tuqquery/tuq.py: cmd = "cd %s/src/github.com/couchbase/query/server/cbq-engine; " % (gopath) +
pytests/tuqquery/tuq.py: "./cbq-engine.exe -datastore http://%s%s:%s/ %s >/dev/null 2>&1 &" %(
pytests/tuqquery/tuq.py: cmd = "cd %s/src/github.com/couchbase/query/server/cbq-engine; " % (gopath) +
pytests/tuqquery/tuq.py: "./cbq-engine -datastore http://%s%s:%s/ %s >n1ql.log 2>&1 &" %(
pytests/tuqquery/tuq.py: "./cbq-engine.exe -datastore http://%s%s:%s/ %s >/dev/null 2>&1 &" %(
pytests/tuqquery/tuq.py: "./cbq-engine -datastore http://%s%s:%s/ %s >/dev/null 2>&1 &" %(
pytests/tuqquery/tuq.py: cmd = "cd /tmp/tuq;./cbq-engine -couchbase http://%s:%s/ >/dev/null 2>&1 &" %(
pytests/tuqquery/tuq.py: cmd = "cd /cygdrive/c/tuq;./cbq-engine.exe -couchbase http://%s:%s/ >/dev/null 2>&1 &" %(

So should i replace the exe with .test binary along with the flag? What will be the args in my case?


(system) #4