-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathxraysummary_test.go
76 lines (66 loc) · 2.05 KB
/
xraysummary_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tests
import (
"bytes"
"encoding/json"
"github.com/stretchr/testify/assert"
"strconv"
"strings"
"testing"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/xray/services"
)
var testsXraySummaryService *services.SummaryService
func TestNewXraySummaryService(t *testing.T) {
initXrayTest(t)
xrayServerPort := xray.StartXrayMockServer(t)
xrayDetails := GetXrayDetails()
client, err := jfroghttpclient.JfrogClientBuilder().
SetClientCertPath(xrayDetails.GetClientCertPath()).
SetClientCertKeyPath(xrayDetails.GetClientCertKeyPath()).
AppendPreRequestInterceptor(xrayDetails.RunPreRequestFunctions).
Build()
if err != nil {
t.Error(err)
}
testsXraySummaryService = services.NewSummaryService(client)
testsXraySummaryService.XrayDetails = xrayDetails
testsXraySummaryService.XrayDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/")
// Run tests
tests := []struct {
name string
checksums []string
paths []string
expected string
}{
{name: "getVulnerableArtifactSummary", checksums: []string{"0000"}, paths: nil, expected: xray.VulnerableXraySummaryArtifactResponse},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
artifactSummary(t, test.checksums, test.paths, test.expected)
})
}
}
func artifactSummary(t *testing.T, checksums []string, paths []string, expected string) {
params := services.ArtifactSummaryParams{
Checksums: checksums,
Paths: paths,
}
result, err := testsXraySummaryService.GetArtifactSummary(params)
if err != nil {
t.Error(err)
}
resultString, err := json.Marshal(result)
if err != nil {
t.Error(err)
}
buf := bytes.NewBuffer([]byte{})
err = json.Compact(buf, []byte(expected))
assert.NoError(t, err)
expected = buf.String()
expected = strings.ReplaceAll(expected, "\n", "")
actual := strings.ReplaceAll(string(resultString), "\n", "")
if actual != expected {
t.Error("\nExpected:\n", expected, "\n\nGot:\n", actual)
}
}