uartois / sonar-golang

Sonarqube plugin for the golang language.
GNU Lesser General Public License v3.0
245 stars 32 forks source link

No unit test results shown or used in SQ 7.0 #64

Closed BillHodghead closed 6 years ago

BillHodghead commented 6 years ago

Description

Does the plugin work in SonarQube 7.0? I haven't yet dropped back to 6.x Although the unit test information appears to import, nothing appears in SonarQube to show the unit test status or failures and no rule is triggered for the unit test failure

Steps to Reproduce

  1. with SonarQube 7.0 installed and the latest scanner and the latest Golang plugin
  2. run the scanner
  3. success, but no data in SQ

Content of your sonar-project.properties

sonar.projectKey=outyet
sonar.projectName=outyet
sonar.projectVersion=1.0 

# GoLint report path, default value is report.xml
sonar.golint.reportPath=lint.xml
# Cobertura like coverage report path, default value is coverage.xml
# sonar.coverage.reportPath=coverage.xml
# if you want disabled the DTD verification for a proxy problem for example, true by default
sonar.coverage.dtdVerification=false
# JUnit like test report, default value is test.xml
sonar.test.reportPath=test.xml
sonar.sources=.
# sonar.coverage.exclusions=vendor/**,bin/**,deploy/**,**/*.xml
# sonar.exclusions=vendor/**,bin/**,deploy/**,**/*.xml
sonar.test.inclusions=**/**_test.go
sonar.sources.inclusions=**/**.go

Log of sonar-scanner related to the plugin

INFO: Scanner configuration file: /root/scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /root/example/outyet/sonar-project.properties
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Linux 4.4.0-72-generic amd64
INFO: User cache: /root/.sonar/cache
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=82ms
INFO: Server id: AWHexoq9AvoOUlyukw6q
INFO: User cache: /root/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=53ms
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=8ms
INFO: SonarQube server 7.0.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=90ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=41ms
INFO: Load active rules
INFO: Load active rules (done) | time=145ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=40ms
WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
INFO: Project key: outyet
INFO: -------------  Scan outyet
INFO: Load server rules
INFO: Load server rules (done) | time=18ms
INFO: Base dir: /root/example/outyet
INFO: Working dir: /root/example/outyet/.scannerwork
INFO: Source paths: .
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: Included sources:
INFO:   **/**.go
INFO: Excluded sources:
INFO:   **/**_test.go
INFO: Included tests:
INFO:   **/**_test.go
INFO: 1 file indexed
INFO: 10 files ignored because of inclusion/exclusion patterns
INFO: Quality profile for go: Golint Test Rules
INFO: Sensor GoMetaLinter issues loader sensor [golang]
INFO: Parsing the file lint.xml
INFO: Parsing 'GoMetaLinter' Analysis Results
INFO: Sensor GoMetaLinter issues loader sensor [golang] (done) | time=18ms
INFO: Sensor Go Coverage [golang]
INFO: /root/example/outyet
INFO: no coverage file in package /root/example/outyet/coverage.xml
INFO: Sensor Go Coverage [golang] (done) | time=4ms
INFO: Sensor Go test JUnit loader sensor [golang]
INFO: base dir /root/example/outyet
INFO: search test function in /root/example/outyet/main_test.go
search function in file /root/example/outyet/main_test.go
WARN: File not found /root/example/outyet/main_test.go
INFO: Sensor Go test JUnit loader sensor [golang] (done) | time=17ms
INFO: Sensor Go Highlighter Sensor [golang]
INFO: Sensor Go Highlighter Sensor [golang] (done) | time=88ms
INFO: Sensor Go Metrics Sensor [golang]
INFO: Sensor Go Metrics Sensor [golang] (done) | time=10ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=18ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer (done) | time=3ms
INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 94ms, dir size=7 KB
INFO: Analysis reports compressed in 15ms, zip size=4 KB
INFO: Analysis report uploaded in 40ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://10.145.85.140:31862/sonar/dashboard/index/outyet
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://10.145.85.140:31862/sonar/api/ce/task?id=AWIB8XkHe3en6OeviJsj
INFO: Task total time: 1.561 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 3.250s
INFO: Final Memory: 43M/103M
INFO: ------------------------------------------------------------------------

Versions

SonarQube 7.0 Plugin 1.2.11

Additional Information

Test.xml

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite tests="2" failures="0" time="0.000" name="">
        <properties>
            <property name="go.version" value="go1.10"></property>
        </properties>
        <testcase classname="" name="TestIsTagged" time="0.000"></testcase>
        <testcase classname="" name="TestIntegration" time="0.000"></testcase>
    </testsuite>
</testsuites>
danielleberre commented 6 years ago

I haven't yet tried release 7.0.

There is the following error message in the log:

WARN: File not found /root/example/outyet/main_test.go

Are you using docker to run the analysis?

BillHodghead commented 6 years ago

Not on docker. Just an Ubuntu VM. The code itself is a simple example: https://github.com/golang/example/tree/master/outyet. That file main_test.go does exist at that location.

That said, the test file is excluded from source and is only used for test scanning. What's missing is import of results from test.xml (included above).

BillHodghead commented 6 years ago

I changed the sonar-project.properties file to

sonar.test.reportPath=./test.xml
sonar.sources=./
sonar.tests=./
sonar.test.inclusions=**/**_test.go
sonar.sources.inclusions=**/**.go

as mentioned in the release notes. This seems to give warnings that indicate the test file is being read, but nothing is showing up on the server for unit tests. Are there unit test attributes that are required and not being created by go test -v ./... | go-junit-report > test.xml?

WARN: /root/example/outyet/main_test.go
WARN: Metric[id=<null>,key=skipped_tests,description=Number of skipped unit tests,type=INT,direction=-1,domain=Coverage,name=Skipped Unit Tests,qualitative=true,userManaged=false,enabled=true,worstValue=<null>,bestValue=0.0,optimizedBestValue=true,hidden=false,deleteHistoricalData=false,decimalScale=<null>]
WARN: /root/example/outyet/main_test.go
WARN: Metric[id=<null>,key=tests,description=Number of unit tests,type=INT,direction=-1,domain=Coverage,name=Unit Tests,qualitative=false,userManaged=false,enabled=true,worstValue=<null>,bestValue=<null>,optimizedBestValue=false,hidden=false,deleteHistoricalData=false,decimalScale=<null>]
WARN: /root/example/outyet/main_test.go
WARN: Metric[id=<null>,key=test_failures,description=Number of unit test failures,type=INT,direction=-1,domain=Coverage,name=Unit Test Failures,qualitative=true,userManaged=false,enabled=true,worstValue=<null>,bestValue=0.0,optimizedBestValue=true,hidden=false,deleteHistoricalData=false,decimalScale=<null>]
WARN: /root/example/outyet/main_test.go
WARN: Metric[id=<null>,key=test_execution_time,description=Execution duration of unit tests,type=MILLISEC,direction=-1,domain=Coverage,name=Unit Test Duration,qualitative=false,userManaged=false,enabled=true,worstValue=<null>,bestValue=<null>,optimizedBestValue=false,hidden=false,deleteHistoricalData=false,decimalScale=<null>]
INFO: Sensor Go test JUnit loader sensor [golang] (done) | time=30ms
INFO: Sensor Go Highlighter Sensor [golang]
INFO: Sensor Go Highlighter Sensor [golang] (done) | time=104ms
INFO: Sensor Go Metrics Sensor [golang]
INFO: Sensor Go Metrics Sensor [golang] (done) | time=5ms
danielleberre commented 6 years ago

Could you add sonar.sources.exclusions=**/**_test.go in sonar-project.properties?

thibaultfalque commented 6 years ago

Hi all, I test the project with sonarqube 6.3. I have no problem. I will explore the problem with sonarqube 7.0.

BillHodghead commented 6 years ago

We dropped back to 6.x and got everything to work. That might not have been needed. The exclusion above certainly helped and also using sed to replace the absolute paths in the coverage file with relative paths. Thanks so much for your help.

thibaultfalque commented 6 years ago

I have test the projet with Sonarqube 7.0 and it's work.

  1. Clone the project
  2. Add a sonar-project.properties with this content:
    sonar.test.reportPath=./test.xml
    sonar.sources=./
    sonar.tests=./
    sonar.test.inclusions=**/**_test.go
    sonar.sources.exclusions=**/**_test.go
    sonar.sources.inclusions=**/**.go
    sonar.projectKey=testIssue64
    sonar.projectName=issue64
    sonar.login=....
  3. gometalinter.v1 --checkstyle > report.xml
  4. go test -v ./... | go-junit-report > test.xml
  5. gocov test ./... | gocov-xml > coverage.xml
  6. Run sonar-scanner

screenshot-localhost 9000-2018-03-19-14-31-35

thibaultfalque commented 6 years ago

@bhcrosslake Could you close this issue if the problem is resolved ?