2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2021-06-23 15:05:00 +02:00
|
|
|
package toolrecord_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-09 10:57:02 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
2021-06-23 15:05:00 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/toolrecord"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestToolRecord(t *testing.T) {
|
2022-07-12 15:19:12 +02:00
|
|
|
workspace := t.TempDir()
|
2021-06-23 15:05:00 +02:00
|
|
|
|
|
|
|
t.Run("Check toolrecord", func(t *testing.T) {
|
2022-08-09 10:57:02 +02:00
|
|
|
fileMock := mock.FilesMock{}
|
|
|
|
tr := toolrecord.New(&fileMock, workspace, "dummyTool", "dummyInstance")
|
2021-06-23 15:05:00 +02:00
|
|
|
|
2022-08-09 10:57:02 +02:00
|
|
|
_ = tr.AddKeyData("Organization", "dummyOrgId", "dummyOrgName", "dummyOrgUrl")
|
|
|
|
_ = tr.AddKeyData("Project", "dummyProjectId", "dummyProjName", "dummyProjUrl")
|
|
|
|
_ = tr.AddKeyData("ScanId", "dummyScanId", "dummyScanName", "dummyScanUrl")
|
2021-06-23 15:05:00 +02:00
|
|
|
context := map[string]interface{}{
|
|
|
|
"demo": "data",
|
|
|
|
"anything": struct {
|
|
|
|
s1 string
|
|
|
|
i1 int
|
|
|
|
}{"goes", 42},
|
|
|
|
}
|
2022-08-09 10:57:02 +02:00
|
|
|
_ = tr.AddContext("DemoContext", context)
|
2021-09-09 10:50:33 +02:00
|
|
|
context2 := "a string"
|
2022-08-09 10:57:02 +02:00
|
|
|
_ = tr.AddContext("Context2", context2)
|
2021-09-09 10:50:33 +02:00
|
|
|
var context3 [2]string
|
|
|
|
context3[0] = "c3_1"
|
|
|
|
context3[1] = "c3_2"
|
2022-08-09 10:57:02 +02:00
|
|
|
_ = tr.AddContext("Context3", context3)
|
2021-06-23 15:05:00 +02:00
|
|
|
err := tr.Persist()
|
|
|
|
assert.Nil(t, err, "internal error %s")
|
2022-08-09 10:57:02 +02:00
|
|
|
assert.True(t, fileMock.HasFile(tr.GetFileName()), "toolrecord not persisted %s")
|
2021-06-23 15:05:00 +02:00
|
|
|
})
|
|
|
|
}
|