forked from jfrog/frogbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscandetails_test.go
77 lines (69 loc) · 2.48 KB
/
scandetails_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
77
package utils
import (
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/stretchr/testify/assert"
"path/filepath"
"testing"
)
func TestCreateXrayScanParams(t *testing.T) {
// Project
scanDetails := &ScanDetails{}
scanDetails.SetXrayGraphScanParams(nil, "", false)
assert.Empty(t, scanDetails.Watches)
assert.Equal(t, "", scanDetails.ProjectKey)
assert.True(t, scanDetails.IncludeVulnerabilities)
assert.False(t, scanDetails.IncludeLicenses)
// Watches
scanDetails.SetXrayGraphScanParams([]string{"watch-1", "watch-2"}, "", false)
assert.Equal(t, []string{"watch-1", "watch-2"}, scanDetails.Watches)
assert.Equal(t, "", scanDetails.ProjectKey)
assert.False(t, scanDetails.IncludeVulnerabilities)
assert.False(t, scanDetails.IncludeLicenses)
// Project
scanDetails.SetXrayGraphScanParams(nil, "project", true)
assert.Empty(t, scanDetails.Watches)
assert.Equal(t, "project", scanDetails.ProjectKey)
assert.False(t, scanDetails.IncludeVulnerabilities)
assert.True(t, scanDetails.IncludeLicenses)
}
func TestRunInstallIfNeeded(t *testing.T) {
scanSetup := ScanDetails{
Project: &Project{},
}
scanSetup.SetFailOnInstallationErrors(true)
assert.NoError(t, scanSetup.runInstallIfNeeded(""))
tmpDir, err := fileutils.CreateTempDir()
assert.NoError(t, err)
defer func() {
err = fileutils.RemoveTempDir(tmpDir)
assert.NoError(t, err)
}()
params := &Project{
InstallCommandName: "echo",
InstallCommandArgs: []string{"Hello"},
}
scanSetup.Project = params
assert.NoError(t, scanSetup.runInstallIfNeeded(tmpDir))
scanSetup.InstallCommandName = "not-exist"
scanSetup.InstallCommandArgs = []string{"1", "2"}
scanSetup.SetFailOnInstallationErrors(false)
assert.NoError(t, scanSetup.runInstallIfNeeded(tmpDir))
params = &Project{
InstallCommandName: "not-existed",
InstallCommandArgs: []string{"1", "2"},
}
scanSetup.Project = params
scanSetup.SetFailOnInstallationErrors(true)
assert.Error(t, scanSetup.runInstallIfNeeded(tmpDir))
}
func TestGetFullPathWorkingDirs(t *testing.T) {
sampleProject := Project{
WorkingDirs: []string{filepath.Join("a", "b"), filepath.Join("a", "b", "c"), ".", filepath.Join("c", "d", "e", "f")},
}
baseWd := "tempDir"
fullPathWds := GetFullPathWorkingDirs(sampleProject.WorkingDirs, baseWd)
expectedWds := []string{filepath.Join("tempDir", "a", "b"), filepath.Join("tempDir", "a", "b", "c"), "tempDir", filepath.Join("tempDir", "c", "d", "e", "f")}
for _, expectedWd := range expectedWds {
assert.Contains(t, fullPathWds, expectedWd)
}
}