-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathxrayscan_test.go
62 lines (55 loc) · 1.94 KB
/
xrayscan_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package tests
import (
"strconv"
"strings"
"testing"
"github.com/jfrog/jfrog-client-go/artifactory/services"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
)
var testsXrayScanService *services.XrayScanService
func TestNewXrayScanService(t *testing.T) {
initXrayTest(t)
xrayServerPort := xray.StartXrayMockServer(t)
artDetails := GetRtDetails()
client, err := jfroghttpclient.JfrogClientBuilder().
SetClientCertPath(artDetails.GetClientCertPath()).
SetClientCertKeyPath(artDetails.GetClientCertKeyPath()).
AppendPreRequestInterceptor(artDetails.RunPreRequestFunctions).
Build()
if err != nil {
t.Error(err)
}
testsXrayScanService = services.NewXrayScanService(client)
testsXrayScanService.ArtDetails = artDetails
testsXrayScanService.ArtDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/")
// Run tests
tests := []struct {
name string
buildName string
buildNumber string
expected string
}{
{name: "scanCleanBuild", buildName: xray.CleanScanBuildName, buildNumber: "3", expected: xray.CleanXrayScanResponse},
{name: "scanVulnerableBuild", buildName: xray.VulnerableBuildName, buildNumber: "3", expected: xray.VulnerableXrayScanResponse},
{name: "scanFatalBuild", buildName: xray.FatalScanBuildName, buildNumber: "3", expected: xray.FatalErrorXrayScanResponse},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
scanBuild(t, test.buildName, test.buildNumber, test.expected)
})
}
}
func scanBuild(t *testing.T, buildName, buildNumber, expected string) {
params := services.NewXrayScanParams()
params.BuildName = buildName
params.BuildNumber = buildNumber
result, err := testsXrayScanService.ScanBuild(params)
if err != nil {
t.Error(err)
}
expected = strings.ReplaceAll(expected, "\n", "")
if string(result) != expected {
t.Error("Expected:", expected, "Got: ", string(result))
}
}