forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
96 lines (83 loc) · 1.83 KB
/
helpers_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package test
import (
"errors"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func Test_GetCurrentDirName(t *testing.T) {
tests := []struct {
name string
path string
expectedOutput string
}{
{
name: "path without \"\"",
path: filepath.Join("some", "valid", "dir"),
expectedOutput: "dir",
},
{
name: "path with \"\"",
path: filepath.Join("some", "valid", "dir") + string(os.PathSeparator),
expectedOutput: "dir",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := GetCurrentDirName(tt.path)
require.Equal(t, tt.expectedOutput, v)
})
}
}
func Test_FormatCurrentDirError(t *testing.T) {
tests := []struct {
name string
value error
expectedOutput string
}{
{
name: "error format test",
value: errors.New("some text"),
expectedOutput: "change path error = some text",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := formatCurrentDirError(tt.value)
require.Equal(t, tt.expectedOutput, v)
})
}
}
func Test_ChangeCurrentDir(t *testing.T) {
tests := []struct {
name string
desiredDir string
startDir string
expectedError bool
}{
{
name: "valid change dir",
startDir: filepath.Join("fixtures"),
desiredDir: "test",
expectedError: false,
},
{
name: "valid change dir",
startDir: filepath.Join("fixtures", "all_auth_users_get_read_access"),
desiredDir: "test",
expectedError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os.Chdir(tt.startDir)
v := ChangeCurrentDir(tt.desiredDir)
if tt.expectedError {
require.Error(t, v)
} else {
require.NoError(t, v)
}
})
}
}