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

Unclear if exclude paths working correctly #102

Open
kelzenberg opened this issue Sep 13, 2024 · 6 comments
Open

Unclear if exclude paths working correctly #102

kelzenberg opened this issue Sep 13, 2024 · 6 comments

Comments

@kelzenberg
Copy link

kelzenberg commented Sep 13, 2024

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
Copy link
Owner

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
Copy link
Author

kelzenberg commented Sep 13, 2024

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
Copy link
Author

kelzenberg commented Sep 13, 2024

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
Copy link
Owner

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
Copy link
Author

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

@vladopajic
Copy link
Owner

hello @kelzenberg, i would like to kindly follow up on this issue. do the exclude paths work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants