2022-02-23 10:30:19 +02:00
|
|
|
//go:build integration
|
2020-02-18 16:19:50 +02:00
|
|
|
// +build integration
|
2022-01-24 14:43:07 +02:00
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
// can be executed with
|
|
|
|
// go test -v -tags integration -run TestSonarIntegration ./integration/...
|
2020-02-18 16:19:50 +02:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-02-24 16:44:23 +02: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 16:19:50 +02:00
|
|
|
)
|
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
func TestSonarIntegrationIssueSearch(t *testing.T) {
|
2021-02-24 16:44:23 +02: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,
|
2023-02-22 11:19:56 +02:00
|
|
|
Severities: "MINOR",
|
2021-02-24 16:44:23 +02:00
|
|
|
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 12:47:13 +02:00
|
|
|
func TestSonarIntegrationMeasuresComponentSearch(t *testing.T) {
|
2021-12-08 10:02:12 +02: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 10:52:29 +02:00
|
|
|
componentService := sonar.NewMeasuresComponentService(host, token, componentKey, organization, "", "", &piperhttp.Client{})
|
2021-12-08 10:02:12 +02:00
|
|
|
// test
|
|
|
|
_, err := componentService.GetCoverage()
|
|
|
|
// assert
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2022-02-04 10:52:29 +02:00
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
func TestSonarIntegrationGetLinesOfCode(t *testing.T) {
|
2022-02-04 10:52:29 +02: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)
|
|
|
|
}
|