-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupload_test.go
More file actions
129 lines (123 loc) · 3.03 KB
/
upload_test.go
File metadata and controls
129 lines (123 loc) · 3.03 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package cmd
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetRelativePath(t *testing.T) {
const baseDir = "/home/user/project/src"
tests := []struct {
name string
baseDir string
fullURI string
expected string
}{
{
name: "1. File URI with standard path",
baseDir: baseDir,
fullURI: "file:///home/user/project/src/lib/file.go",
expected: "lib/file.go",
},
{
name: "2. File URI with baseDir as the file path",
baseDir: baseDir,
fullURI: "file:///home/user/project/src",
expected: ".",
},
{
name: "3. Simple path (no scheme)",
baseDir: baseDir,
fullURI: "/home/user/project/src/main.go",
expected: "main.go",
},
{
name: "4. URI outside baseDir (should return absolute path if relative fails)",
baseDir: baseDir,
fullURI: "file:///etc/config/app.json",
// This is outside of baseDir, so we expect the absolute path starting from the baseDir root
expected: "../../../../etc/config/app.json",
},
{
name: "5. Plain URI with different scheme (should be treated as plain path)",
baseDir: baseDir,
fullURI: "http://example.com/api/v1/file.go",
expected: "http://example.com/api/v1/file.go",
},
{
name: "6. Empty URI",
baseDir: baseDir,
fullURI: "",
expected: "",
},
{
name: "7. Windows path on a file URI (should correctly strip the leading slash from the path component)",
baseDir: "C:\\Users\\dev\\repo",
fullURI: "file:///C:/Users/dev/repo/app/main.go",
expected: "/C:/Users/dev/repo/app/main.go",
},
{
name: "8. URI with spaces (URL encoded)",
baseDir: baseDir,
fullURI: "file:///home/user/project/src/file%20with%20spaces.go",
expected: "file with spaces.go",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := getRelativePath(tt.baseDir, tt.fullURI)
expectedNormalized := filepath.FromSlash(tt.expected)
assert.Equal(t, expectedNormalized, actual, "Relative path should match expected")
})
}
}
func TestGetToolShortName(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "MappedTool_ESLint8",
input: "ESLint",
expected: "eslint-8",
},
{
name: "MappedTool_PMD7",
input: "PMD7",
expected: "pmd-7",
},
{
name: "MappedTool_Pylint",
input: "Pylint",
expected: "pylintpython3",
},
{
name: "UnmappedTool_Fallback",
input: "NewToolName",
expected: "NewToolName",
},
{
name: "UnmappedTool_AnotherFallback",
input: "SomeAnalyzer",
expected: "SomeAnalyzer",
},
{
name: "EmptyInput_Fallback",
input: "",
expected: "",
},
{
name: "MappedTool_Deprecated",
input: "ESLint (deprecated)",
expected: "eslint",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := getToolShortName(tt.input)
if actual != tt.expected {
t.Errorf("getToolShortName(%q) = %q; want %q", tt.input, actual, tt.expected)
}
})
}
}