vladopajic / go-test-coverage

go-test-coverage is tool and github action which reports issues when test coverage is below set threshold
GNU General Public License v3.0
81 stars 10 forks source link

Unclear if exclude paths working correctly #102

Open kelzenberg opened 4 days ago

kelzenberg commented 4 days ago

I'm trying to run the go-test-coverage but it constantly ignores my excluded paths/files.

./.testcoverage.yml

profile: ./cover.out
local-prefix: "broker"
threshold:
  file: 70
  package: 80
  total: 90
override:
  - threshold: 0
    path: ^.*cmd
exclude:
  paths:
    - ^.*models

Command

go-test-coverage --config=./.testcoverage.yml

Output

Files meeting coverage threshold of (70%):  FAIL

Issues with:
broker/cmd/main.go                      0%
# [...] shortened for readability
::error file=broker/models/mssql/Xm.go,line=1::File test coverage below threshold of (70%)
::error ::Package (broker/models/mssql) test coverage below threshold of (80%)
# [...] shortened for readability
::error ::Total coverage below threshold of (90%)

As you can see, the overridden threshold for $root/cmd files is ignored and the $root/models folder is not excluded. I also tried the following exclude path regex for models:

- ^models
- ^.*models
- ^.*models/
- ^.*\/models\/
- ^broker/models

What am I missing here?

vladopajic commented 4 days ago

hey

i am not really sure what is happening here, but override and exclude rules are working correctly in all my repositories.

does local-prefix have same value as module in go.mod file?

in the output that you provided, broker/models or ^broker/models should exclude this package. first rule is bit more relaxed, because it will exclude any file that contains broker/models in it's path (maybe try with this?), while second will exclude files that begins with this string. it looks to me that, for some reason, paths might not begin with broker/models although that's what output indicates.

to enure that rule is actually working, try excluding some specif file. for example have exclude rule with Xm\.go$ (i see you have this file in output provided above broker/models/mssql/Xm.go ).

kelzenberg commented 4 days ago

does local-prefix have same value as module in go.mod file?

Yes, it does.

With - Xm\.go$ and even - main\.go$ excluded I still get

Issues with:
broker/cmd/main.go                          0%
::error file=broker/models/mssql/Xm.go,line=1::File test coverage below threshold of (70%)
::error file=broker/cmd/main.go,line=1::File test coverage below threshold of (70%)

I'm running go-test-coverage --config=./.testcoverage.yml locally, even reinstalled it globally from scratch, and I know that the lib is reading the config file because changing the profile to ./foo.out is throwing an error. But I can't figure out why override and exclude are misbehaving...

kelzenberg commented 4 days ago

I might have to add that the folder I'm executing the command is a subfolder of a monorepo but that shouldn't matter AFAIK.

Repo looks like this

| repo-root/
|-- broker/ # go-test-coverage executed in this folder
|---- go.mod
|---- .testcoverage.yml
|---- cmd/
|---- models/
|-- other-service/

Edit: And maybe it's a MacOS 14.6.1 thing? Running the binary on M3.

vladopajic commented 4 days ago

And maybe it's a MacOS 14.6.1 thing

i am really not sure.

if you can clone repo and run it as source go run ./path-to-go-test-coverage/main.go --config=... i think you can easily identify problem, and maybe open PR with a fix 💕.

everything happens here.

kelzenberg commented 4 days ago

I'll try it on a minimal repo, plus from source, and report back. Thanks for the quick assessment 🙌