github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/toolrecord/toolrecord_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package toolrecord_test 5 6 import ( 7 "testing" 8 9 "github.com/SAP/jenkins-library/pkg/mock" 10 "github.com/SAP/jenkins-library/pkg/toolrecord" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestToolRecord(t *testing.T) { 15 workspace := t.TempDir() 16 17 t.Run("Check toolrecord", func(t *testing.T) { 18 fileMock := mock.FilesMock{} 19 tr := toolrecord.New(&fileMock, workspace, "dummyTool", "dummyInstance") 20 21 _ = tr.AddKeyData("Organization", "dummyOrgId", "dummyOrgName", "dummyOrgUrl") 22 _ = tr.AddKeyData("Project", "dummyProjectId", "dummyProjName", "dummyProjUrl") 23 _ = tr.AddKeyData("ScanId", "dummyScanId", "dummyScanName", "dummyScanUrl") 24 context := map[string]interface{}{ 25 "demo": "data", 26 "anything": struct { 27 s1 string 28 i1 int 29 }{"goes", 42}, 30 } 31 _ = tr.AddContext("DemoContext", context) 32 context2 := "a string" 33 _ = tr.AddContext("Context2", context2) 34 var context3 [2]string 35 context3[0] = "c3_1" 36 context3[1] = "c3_2" 37 _ = tr.AddContext("Context3", context3) 38 err := tr.Persist() 39 assert.Nil(t, err, "internal error %s") 40 assert.True(t, fileMock.HasFile(tr.GetFileName()), "toolrecord not persisted %s") 41 }) 42 }