-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindexec_test.go
More file actions
79 lines (68 loc) · 2.14 KB
/
findexec_test.go
File metadata and controls
79 lines (68 loc) · 2.14 KB
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
78
79
package findexec
import (
"os"
"runtime"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
var osPathSep = string(os.PathListSeparator)
func TestFindAbsExisting(t *testing.T) {
if runtime.GOOS == "windows" {
assert.Equal(t, "C:\\Windows\\system32\\cmd.exe",
Find("C:\\Windows\\system32\\cmd.exe", ""))
} else {
assert.Equal(t, "/bin/sh", Find("/bin/sh", ""))
}
}
func TestFindExpectExist(t *testing.T) {
if runtime.GOOS == "windows" {
assert.Equal(t, "C:\\Windows\\system32\\cmd.exe", Find("cmd.exe", ""))
} else {
assert.Equal(t, "/bin/sh", Find("sh", ""))
}
}
func TestFindExpectNotExisting(t *testing.T) {
assert.Equal(t, "", Find("something_that_does_not_exist", ""))
}
func TestFindExpectExistWithSuppliedPath(t *testing.T) {
if runtime.GOOS == "windows" {
assert.Equal(t, "C:\\Windows\\system32\\cmd.exe",
Find("cmd.exe", "C:\\Windows\\system32"))
} else {
assert.Equal(t, "/bin/sh", Find("sh", "/bin"))
}
}
func TestFindExpectExistWithMultipleSuppliedPaths(t *testing.T) {
if runtime.GOOS == "windows" {
paths := strings.Join([]string{"C:\\invalidOne", "D:\\invalidTwo", "C:\\Windows\\system32"}, osPathSep)
assert.Equal(t, "C:\\Windows\\system32\\cmd.exe", Find("cmd.exe", paths))
} else {
paths := strings.Join([]string{"/invalidOne", "/invalidTwo", "/bin"}, osPathSep)
assert.Equal(t, "/bin/sh", Find("sh", paths))
}
}
func TestFindExpectNotExistingWithSuppliedPath(t *testing.T) {
if runtime.GOOS == "windows" {
assert.Equal(t, "", Find("cmd.exe", "C:\\invalidOne"))
} else {
assert.Equal(t, "", Find("sh", "/invalid"))
}
}
func TestFindExpectNotExistingWithMultipleSuppliedPaths(t *testing.T) {
if runtime.GOOS == "windows" {
paths := strings.Join([]string{"C:\\invalidOne", "C:\\invalidTwo"}, osPathSep)
assert.Equal(t, "", Find("cmd.exe", paths))
} else {
paths := strings.Join([]string{"/invalidOne", "/invalidTwo", "/invalidThree"}, osPathSep)
assert.Equal(t, "", Find("sh", paths))
}
}
func TestFindWithMissingOSPATHs(t *testing.T) {
_ = os.Setenv("PATH", "")
if runtime.GOOS == "windows" {
assert.Equal(t, "", Find("cmd.exe", ""))
} else {
assert.Equal(t, "", Find("sh", ""))
}
}