-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathplugin_test.go
More file actions
91 lines (84 loc) · 2.09 KB
/
plugin_test.go
File metadata and controls
91 lines (84 loc) · 2.09 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
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestIsDir(t *testing.T) {
// Create temporary directory for testing
tmpDir := t.TempDir()
testDir := filepath.Join(tmpDir, "testdir")
testFile := filepath.Join(tmpDir, "testfile.txt")
// Create a test directory
err := os.Mkdir(testDir, 0755)
if err != nil {
t.Fatalf("Failed to create test directory: %v", err)
}
// Create a test file
file, err := os.Create(testFile)
if err != nil {
t.Fatalf("Failed to create test file: %v", err)
}
file.Close()
tests := []struct {
name string
source string
matches []string
expectError bool
expectSkip bool
errorContains string
}{
{
name: "file should not error",
source: testFile,
matches: []string{testFile},
expectError: false,
expectSkip: false,
},
{
name: "directory without glob should error",
source: testDir,
matches: []string{testDir},
expectError: true,
expectSkip: false,
errorContains: "specified without glob pattern",
},
{
name: "directory with glob pattern should skip",
source: testDir,
matches: []string{testDir + "/file1.txt", testDir + "/file2.txt"},
expectError: false,
expectSkip: true,
},
{
name: "non-existent path should skip",
source: "/non/existent/path",
matches: []string{},
expectError: false,
expectSkip: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := isDir(tc.source, tc.matches)
if tc.expectError {
if err == nil {
t.Errorf("Expected error but got none")
} else if err == errSkip {
t.Errorf("Expected fatal error but got skip error")
} else if tc.errorContains != "" && !strings.Contains(err.Error(), tc.errorContains) {
t.Errorf("Expected error to contain '%s', but got: %v", tc.errorContains, err)
}
} else if tc.expectSkip {
if err != errSkip {
t.Errorf("Expected skip error but got: %v", err)
}
} else {
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
}
})
}
}