Golang: WARN: Failed to read package directory

On Sonarqube, code coverage is displayed, but unit tests reports are not.
Project structure:

/
  go.mod // declaring module git.hjkl.gq/team13/birdazzone-api
  go.sum
  main.go // declaring package main
  main_test.go // declaring package main
  sonar-project.properties

I checked on GitLab Runners, and the report.json artifact is correctly generated:

{"Time":"2022-11-01T10:53:56.916199079+01:00","Action":"run","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackSuccess"}
{"Time":"2022-11-01T10:53:56.916792481+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackSuccess","Output":"=== RUN   TestLookupEnvWithFallbackSuccess\n"}
{"Time":"2022-11-01T10:53:56.917068183+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackSuccess","Output":"--- PASS: TestLookupEnvWithFallbackSuccess (0.00s)\n"}
{"Time":"2022-11-01T10:53:56.917227823+01:00","Action":"pass","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackSuccess","Elapsed":0}
{"Time":"2022-11-01T10:53:56.917488232+01:00","Action":"run","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackFailure"}
{"Time":"2022-11-01T10:53:56.917635892+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackFailure","Output":"=== RUN   TestLookupEnvWithFallbackFailure\n"}
{"Time":"2022-11-01T10:53:56.91778867+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackFailure","Output":"--- PASS: TestLookupEnvWithFallbackFailure (0.00s)\n"}
{"Time":"2022-11-01T10:53:56.917942834+01:00","Action":"pass","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestLookupEnvWithFallbackFailure","Elapsed":0}
{"Time":"2022-11-01T10:53:56.918091851+01:00","Action":"run","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestAddress"}
{"Time":"2022-11-01T10:53:56.918238523+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestAddress","Output":"=== RUN   TestAddress\n"}
{"Time":"2022-11-01T10:53:56.918398795+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestAddress","Output":"--- PASS: TestAddress (0.00s)\n"}
{"Time":"2022-11-01T10:53:56.918546323+01:00","Action":"pass","Package":"git.hjkl.gq/team13/birdazzone-api","Test":"TestAddress","Elapsed":0}
{"Time":"2022-11-01T10:53:56.91869083+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Output":"PASS\n"}
{"Time":"2022-11-01T10:53:56.918834815+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Output":"coverage: 10.4% of statements\n"}
{"Time":"2022-11-01T10:53:56.930867572+01:00","Action":"output","Package":"git.hjkl.gq/team13/birdazzone-api","Output":"ok  \tgit.hjkl.gq/team13/birdazzone-api\t0.093s\n"}
{"Time":"2022-11-01T10:53:56.931145815+01:00","Action":"pass","Package":"git.hjkl.gq/team13/birdazzone-api","Elapsed":0.094}
  • CI system used: GitLab Runners
stages:
  - build
  - test
  - lint
  - deploy

tests:
  image: golang:1.18
  stage: test
  artifacts:
    paths:
      - coverage.out
      - report.json
    expire_in: 1 week
  script:
    - go test -coverprofile=coverage.out -json > report.json
  only:
    - merge_requests
    - develop

code-quality:
  stage: lint
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
    GIT_DEPTH: "0"
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
   - develop
  • Languages of the repository: Go
  • Error observed:
$ sonar-scanner
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /builds/team13/birdazzone-api/sonar-project.properties
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.17 Alpine (64-bit)
INFO: Linux 5.10.0-18-amd64 amd64
INFO: User cache: /builds/team13/birdazzone-api/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /builds/team13/birdazzone-api/sonar-project.properties
INFO: Analyzing on SonarQube server 9.7.0.61563
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=276ms
INFO: Server id: AA2DD71C-AYOzQde59CwiXExRRnSP
INFO: User cache: /builds/team13/birdazzone-api/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=67ms
INFO: Load/download plugins (done) | time=5344ms
INFO: Process project properties
INFO: Process project properties (done) | time=13ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: birdazzone_birdazzone_AYPTe6hijP-lRCpIv8e6
INFO: Base dir: /builds/team13/birdazzone-api
INFO: Working dir: /builds/team13/birdazzone-api/.scannerwork
INFO: Load project settings for component key: 'birdazzone_birdazzone_AYPTe6hijP-lRCpIv8e6'
INFO: Load project settings for component key: 'birdazzone_birdazzone_AYPTe6hijP-lRCpIv8e6' (done) | time=35ms
INFO: Auto-configuring with CI 'Gitlab CI'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=67ms
INFO: Load active rules
INFO: Load active rules (done) | time=2508ms
INFO: Load analysis cache
INFO: Load analysis cache (404) | time=13ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=22ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/*_test.go, **/*_test.go
INFO:   Included tests: **/*_test.go
INFO: 13 files indexed
INFO: 15 files ignored because of inclusion/exclusion patterns
INFO: 2 files ignored because of scm ignore settings
INFO: Quality profile for go: Sonar way
INFO: Quality profile for json: Sonar way
INFO: Quality profile for yaml: Sonar way
INFO: ------------- Run sensors on module Birdazzone API
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=30ms
INFO: Sensor Code Quality and Security for Go [go]
INFO: 3 source files to be analyzed
INFO: 3/3 source files have been analyzed
INFO: Sensor Code Quality and Security for Go [go] (done) | time=343ms
INFO: Sensor Go Unit Test Report [go]
WARN: Failed to read package directory /builds/team13/birdazzone-api/birdazzone-api
java.nio.file.NotDirectoryException: /builds/team13/birdazzone-api/birdazzone-api
	at java.base/sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:431)
	at java.base/java.nio.file.Files.newDirectoryStream(Files.java:472)
	at java.base/java.nio.file.Files.list(Files.java:3699)
	at org.sonar.go.testreport.GoTestSensor.getTestFilesForPackage(GoTestSensor.java:166)
	at org.sonar.go.testreport.GoTestSensor.lambda$findTestFile$6(GoTestSensor.java:139)
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
	at org.sonar.go.testreport.GoTestSensor.findTestFile(GoTestSensor.java:137)
	at org.sonar.go.testreport.GoTestSensor.parseReport(GoTestSensor.java:106)
	at org.sonar.go.testreport.GoTestSensor.lambda$execute$1(GoTestSensor.java:75)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.sonar.go.testreport.GoTestSensor.execute(GoTestSensor.java:75)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:399)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:395)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:364)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:135)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
WARN: Failed to find test file for package git.hjkl.gq/team13/birdazzone-api and test TestLookupEnvWithFallbackSuccess
WARN: Failed to find test file for package git.hjkl.gq/team13/birdazzone-api and test TestLookupEnvWithFallbackFailure
WARN: Failed to find test file for package git.hjkl.gq/team13/birdazzone-api and test TestAddress

Hi,

Welcome to the community!

You’re getting a

It looks like either the path to the report is misconfigured, or a path in the report is wrong.

 
HTH,
Ann

Thanks for your reply! As both reports are correctly located (according to the log), I assumed that missing directory was a missing /build folder(?). I eventually gave up on this.