Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% test coverage #918

Closed
anderseknert opened this issue Jul 16, 2024 · 0 comments · Fixed by #1074
Closed

100% test coverage #918

anderseknert opened this issue Jul 16, 2024 · 0 comments · Fixed by #1074
Labels
good first issue Good for newcomers

Comments

@anderseknert
Copy link
Member

While this is mostly an expensive waste of time in most languages, it's fairly easy to achieve 100% test coverage in Rego, and without ever having to test "impossible" conditions. The fact that we've never measured test coverage in Regal and despite that have one above 98% is some evidence of that.

go run main.go test --coverage bundle
...
"not_covered_lines": 78,
"coverage": 98.1994459833795

It would be a useful exercise to get that number to 100% to see if there is anything important we currently miss in our tests. Once we have 100% coverage, we should add a build step that enforces that going forward.

In order to see which lines aren't covered, just run go run main.go test --coverage bundle and search the output for "not_covered".

@anderseknert anderseknert added the good first issue Good for newcomers label Jul 16, 2024
anderseknert added a commit that referenced this issue Sep 8, 2024
Like with previous PR aiming to increase our test coverage (#1058),
doing so this time revealed a few places where code was unused, or
could be rewritten to be better optimized, removed, or made easier
to read.

One find that is yet to be addressed here is how we copy the whole
`ast.found.refs` object into `ast.all_refs`, which surely comes with
a cost that seems unnecessary, given we can use `ast.found.refs`
directly instead. But since there are a few consumers, and they are
not **exactly** identical (`all_refs` contains import refs too),
I'll follow up on that in a later PR.

I'm also adding the codecov badge to the README to make it easy to
see when our coverage drops. But I'm not as convinced we should
fail PRs when coverage isn't 100% as I was before, as it might make
for a worse contributor experience.

Fixes #918

Signed-off-by: Anders Eknert <[email protected]>
anderseknert added a commit that referenced this issue Sep 8, 2024
Like with previous PR aiming to increase our test coverage (#1058),
doing so this time revealed a few places where code was unused, or
could be rewritten to be better optimized, removed, or made easier
to read.

One find that is yet to be addressed here is how we copy the whole
`ast.found.refs` object into `ast.all_refs`, which surely comes with
a cost that seems unnecessary, given we can use `ast.found.refs`
directly instead. But since there are a few consumers, and they are
not **exactly** identical (`all_refs` contains import refs too),
I'll follow up on that in a later PR.

I'm also adding the codecov badge to the README to make it easy to
see when our coverage drops. But I'm not as convinced we should
fail PRs when coverage isn't 100% as I was before, as it might make
for a worse contributor experience.

Fixes #918

Signed-off-by: Anders Eknert <[email protected]>
anderseknert added a commit that referenced this issue Sep 8, 2024
Like with previous PR aiming to increase our test coverage (#1058),
doing so this time revealed a few places where code was unused, or
could be rewritten to be better optimized, removed, or made easier
to read.

One find that is yet to be addressed here is how we copy the whole
`ast.found.refs` object into `ast.all_refs`, which surely comes with
a cost that seems unnecessary, given we can use `ast.found.refs`
directly instead. But since there are a few consumers, and they are
not **exactly** identical (`all_refs` contains import refs too),
I'll follow up on that in a later PR.

I'm also adding the codecov badge to the README to make it easy to
see when our coverage drops. But I'm not as convinced we should
fail PRs when coverage isn't 100% as I was before, as it might make
for a worse contributor experience.

Fixes #918

Signed-off-by: Anders Eknert <[email protected]>
anderseknert added a commit that referenced this issue Sep 8, 2024
Like with previous PR aiming to increase our test coverage (#1058),
doing so this time revealed a few places where code was unused, or
could be rewritten to be better optimized, removed, or made easier
to read.

One find that is yet to be addressed here is how we copy the whole
`ast.found.refs` object into `ast.all_refs`, which surely comes with
a cost that seems unnecessary, given we can use `ast.found.refs`
directly instead. But since there are a few consumers, and they are
not **exactly** identical (`all_refs` contains import refs too),
I'll follow up on that in a later PR.

I'm also adding the codecov badge to the README to make it easy to
see when our coverage drops. But I'm not as convinced we should
fail PRs when coverage isn't 100% as I was before, as it might make
for a worse contributor experience.

Fixes #918

Signed-off-by: Anders Eknert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant