Golang test coverage not works as I expect

Technical context:

  • Language: Golang
  • Tool: SonarQube
  • Focus: Test coverage configuration
  • Goal: Directory-specific coverage metrics

I’m trying to configure SonarQube to show test coverage specifically for my server code. Currently, SonarQube calculates and displays coverage metrics for the entire codebase, but I need to restrict the coverage analysis to specific directories. What’s the recommended configuration to exclude certain directories from the coverage calculation and only include the ones I want to measure?

My folder structure example:

├── my_svc
│   ├── cmd
│   │   ├── event_bus
│   │   └── server
│   ├── etc
│   ├── internal
│   │   ├── application
│   │   │   ├── some_test.go
│   │   ├── config
│   │   ├── domain
│   │   │   ├── adapter
│   │   │   ├── entity
│   │   │   │   ├── some_test.go
│   │   │   └── repository
│   │   ├── endpoint
│   │   ├── event
│   │   ├── infrastructure
│   │   │   ├── persistence
│   │   │   └── routing
│   │   ├── svc
│   │   ├── transport
│   │   └── types

My sonarqube properties

sonar.sources=.

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
sonar.go.coverage.reportPaths=bin/cov.out

sonar.exclusions=\
    **/ent/*.go,\
    **/*_mock.go,\
    **/*.pb.go

sonar.issue.ignore.multicriteria=d1,d2,g1,g2,g3,g4,g5

sonar.issue.ignore.multicriteria.d1.ruleKey=docker:S7018
sonar.issue.ignore.multicriteria.d1.resourceKey=**/Dockerfile

sonar.issue.ignore.multicriteria.d2.ruleKey=docker:S7020
sonar.issue.ignore.multicriteria.d2.resourceKey=**/Dockerfile

sonar.issue.ignore.multicriteria.g1.ruleKey=go:S107
sonar.issue.ignore.multicriteria.g1.resourceKey=**/*.go

sonar.issue.ignore.multicriteria.g2.ruleKey=go:S1135
sonar.issue.ignore.multicriteria.g2.resourceKey=**/*.go

sonar.issue.ignore.multicriteria.g3.ruleKey=go:S1192
sonar.issue.ignore.multicriteria.g3.resourceKey=**/*.go

sonar.issue.ignore.multicriteria.g4.ruleKey=go:S3776
sonar.issue.ignore.multicriteria.g4.resourceKey=**/*.go

sonar.issue.ignore.multicriteria.g5.ruleKey=go:S4144
sonar.issue.ignore.multicriteria.g5.resourceKey=**/*.go

I want sonarqube to get test coverage from domain and application folder only.