1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/sonar/sonar_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

45 lines
1.4 KiB
Go

//go:build unit
// +build unit
package sonar
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadTaskReport(t *testing.T) {
t.Run("default", func(t *testing.T) {
// test
result, err := ReadTaskReport("./testData/valid")
// assert
assert.Equal(t, "piper-test", result.ProjectKey)
assert.Equal(t, "AXERR2JBbm9IiM5TEST", result.TaskID)
assert.Equal(t, "https://sonarcloud.io/api/ce/task?id=AXERR2JBbm9IiMTEST", result.TaskURL)
assert.Equal(t, "https://sonarcloud.io/dashboard/index/piper-test", result.DashboardURL)
assert.Equal(t, "https://sonarcloud.io", result.ServerURL)
assert.Equal(t, "8.0.0.12345", result.ServerVersion)
assert.NoError(t, err)
})
t.Run("missing file", func(t *testing.T) {
// test
result, err := ReadTaskReport("./testData/missing")
// assert
assert.Empty(t, result.ProjectKey)
assert.True(t,
(filepath.FromSlash("open testData/missing/.scannerwork/report-task.txt: The system cannot find the path specified.") == err.Error()) ||
(filepath.FromSlash("open testData/missing/.scannerwork/report-task.txt: no such file or directory") == err.Error()))
})
t.Run("invalid file", func(t *testing.T) {
// test
result, err := ReadTaskReport("./testData/invalid")
// assert
assert.Empty(t, result.ProjectKey)
assert.EqualError(t, err, filepath.FromSlash("decode testData/invalid/.scannerwork/report-task.txt: missing required key projectKey"))
})
}