2022-02-23 09:30:19 +01:00
|
|
|
//go:build integration
|
2020-02-18 15:19:50 +01:00
|
|
|
// +build integration
|
2022-01-24 13:43:07 +01:00
|
|
|
|
2022-09-19 14:47:13 +04:00
|
|
|
// can be executed with
|
|
|
|
// go test -v -tags integration -run TestSonarIntegration ./integration/...
|
2020-02-18 15:19:50 +01:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-02-24 15:44:23 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/sonar"
|
2020-02-18 15:19:50 +01:00
|
|
|
)
|
|
|
|
|
2022-09-19 14:47:13 +04:00
|
|
|
func TestSonarIntegrationIssueSearch(t *testing.T) {
|
2021-02-24 15:44:23 +01:00
|
|
|
t.Parallel()
|
|
|
|
// init
|
|
|
|
token := os.Getenv("PIPER_INTEGRATION_SONAR_TOKEN")
|
|
|
|
require.NotEmpty(t, token, "SonarQube API Token is missing")
|
|
|
|
host := os.Getenv("PIPER_INTEGRATION_SONAR_HOST")
|
|
|
|
if len(host) == 0 {
|
|
|
|
host = "https://sonarcloud.io"
|
|
|
|
}
|
|
|
|
organization := os.Getenv("PIPER_INTEGRATION_SONAR_ORGANIZATION")
|
|
|
|
if len(organization) == 0 {
|
|
|
|
organization = "sap-1"
|
|
|
|
}
|
|
|
|
componentKey := os.Getenv("PIPER_INTEGRATION_SONAR_PROJECT")
|
|
|
|
if len(componentKey) == 0 {
|
|
|
|
componentKey = "SAP_jenkins-library"
|
|
|
|
}
|
|
|
|
options := &sonar.IssuesSearchOption{
|
|
|
|
ComponentKeys: componentKey,
|
|
|
|
Severities: "INFO",
|
|
|
|
Resolved: "false",
|
|
|
|
Ps: "1",
|
|
|
|
Organization: organization,
|
|
|
|
}
|
|
|
|
issueService := sonar.NewIssuesService(host, token, componentKey, organization, "", "", &piperhttp.Client{})
|
|
|
|
// test
|
|
|
|
result, _, err := issueService.SearchIssues(options)
|
|
|
|
// assert
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, result.Components)
|
|
|
|
//FIXME: include once implememnted
|
|
|
|
// assert.NotEmpty(t, result.Organizations)
|
|
|
|
}
|
|
|
|
|
2022-09-19 14:47:13 +04:00
|
|
|
func TestSonarIntegrationMeasuresComponentSearch(t *testing.T) {
|
2021-12-08 09:02:12 +01:00
|
|
|
t.Parallel()
|
|
|
|
// init
|
|
|
|
token := os.Getenv("PIPER_INTEGRATION_SONAR_TOKEN")
|
|
|
|
require.NotEmpty(t, token, "SonarQube API Token is missing")
|
|
|
|
host := os.Getenv("PIPER_INTEGRATION_SONAR_HOST")
|
|
|
|
if len(host) == 0 {
|
|
|
|
host = "https://sonarcloud.io"
|
|
|
|
}
|
|
|
|
organization := os.Getenv("PIPER_INTEGRATION_SONAR_ORGANIZATION")
|
|
|
|
if len(organization) == 0 {
|
|
|
|
organization = "sap-1"
|
|
|
|
}
|
|
|
|
componentKey := os.Getenv("PIPER_INTEGRATION_SONAR_PROJECT")
|
|
|
|
if len(componentKey) == 0 {
|
|
|
|
componentKey = "SAP_jenkins-library"
|
|
|
|
}
|
|
|
|
|
2022-02-04 09:52:29 +01:00
|
|
|
componentService := sonar.NewMeasuresComponentService(host, token, componentKey, organization, "", "", &piperhttp.Client{})
|
2021-12-08 09:02:12 +01:00
|
|
|
// test
|
|
|
|
_, err := componentService.GetCoverage()
|
|
|
|
// assert
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2022-02-04 09:52:29 +01:00
|
|
|
|
2022-09-19 14:47:13 +04:00
|
|
|
func TestSonarIntegrationGetLinesOfCode(t *testing.T) {
|
2022-02-04 09:52:29 +01:00
|
|
|
t.Parallel()
|
|
|
|
// init
|
|
|
|
token := os.Getenv("PIPER_INTEGRATION_SONAR_TOKEN")
|
|
|
|
require.NotEmpty(t, token, "SonarQube API Token is missing")
|
|
|
|
host := os.Getenv("PIPER_INTEGRATION_SONAR_HOST")
|
|
|
|
if len(host) == 0 {
|
|
|
|
host = "https://sonarcloud.io"
|
|
|
|
}
|
|
|
|
organization := os.Getenv("PIPER_INTEGRATION_SONAR_ORGANIZATION")
|
|
|
|
if len(organization) == 0 {
|
|
|
|
organization = "sap-1"
|
|
|
|
}
|
|
|
|
componentKey := os.Getenv("PIPER_INTEGRATION_SONAR_PROJECT")
|
|
|
|
if len(componentKey) == 0 {
|
|
|
|
componentKey = "SAP_jenkins-library"
|
|
|
|
}
|
|
|
|
|
|
|
|
componentService := sonar.NewMeasuresComponentService(host, token, componentKey, organization, "", "", &piperhttp.Client{})
|
|
|
|
// test
|
|
|
|
_, err := componentService.GetLinesOfCode()
|
|
|
|
// assert
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|