1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-08 04:21:26 +02:00
sap-jenkins-library/integration/integration_sonar_test.go
Alexey Matvievsky e5f2f1414e
Improve integration tests (#4019)
Improve integration tests
2022-09-19 14:47:13 +04:00

103 lines
2.9 KiB
Go

//go:build integration
// +build integration
// can be executed with
// go test -v -tags integration -run TestSonarIntegration ./integration/...
package main
import (
"os"
"testing"
"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"
)
func TestSonarIntegrationIssueSearch(t *testing.T) {
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)
}
func TestSonarIntegrationMeasuresComponentSearch(t *testing.T) {
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.GetCoverage()
// assert
assert.NoError(t, err)
}
func TestSonarIntegrationGetLinesOfCode(t *testing.T) {
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)
}