kyverno icon indicating copy to clipboard operation
kyverno copied to clipboard

[Feature] Run CLI tests via the go test runner and record coverage

Open sambhav opened this issue 3 years ago • 7 comments

Problem Statement

Currently we run the CLI tests by compiling the CLI and then invoking kyverno test/apply on the compiled CLI. We should instead just call these commands programatically from go test code so that we can also capture the coverage metrics from our vast array of CLI tests.

Solution Description

We need to refactor the CLI to not call os.Exit at random places in the code base and instead return appropriate error. Once this is done, we can use test the cobra commands programatically in go test code. We should also include these tests when capturing coverage metrics.

Alternatives

n/a

Additional Context

Currently our coverage metrics do not account for coverage of our code base due to CLI tests. We should also capture this.

Slack discussion

No response

Research

  • [X] I have read and followed the documentation AND the troubleshooting guide.
  • [X] I have searched other issues in this repository and mine is not recorded.

sambhav avatar Apr 26 '22 14:04 sambhav

@samj1912 I would love to work on this. Can you please assign me?

kranurag7 avatar May 10 '22 01:05 kranurag7

@samj1912 I have worked on the issue. First I have removed all the os.Exit(1) under the cmd/cli/kubectl-kyverno directory. Now, the default error is getting passed through fmt.Print(err) mostly. One more thing is that I need to pass the files that the test in depending on while executing the command, otherwise it's throwing an error. It's similar for other two generate and report Screenshot from 2022-05-14 20-11-25 I'm not sure if this is what we are trying to achieve. Please guide me further.

kranurag7 avatar May 14 '22 14:05 kranurag7

Hey, @samj1912 I wanna give it a try. Can you please assign it to me? Thanks,

SD-13 avatar Jan 22 '23 18:01 SD-13

This Go 1.20 feature may be worth looking into:

https://www.mgasch.com/2023/02/go-e2e/?s=31

JimBugwadia avatar Feb 08 '23 17:02 JimBugwadia

can you please explain the issue?

sidjaiswal2003 avatar Oct 03 '23 07:10 sidjaiswal2003

@JimBugwadia i would like to work on this issue, I am hoping that this is still not resolved

coder12git avatar Jan 15 '24 02:01 coder12git

/assign

coder12git avatar Jan 15 '24 02:01 coder12git