forked from drone-plugins/drone-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_unix_test.go
130 lines (122 loc) · 2.62 KB
/
plugin_unix_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
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
130
//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
package main
import (
"testing"
)
func TestResolveUnixKey(t *testing.T) {
tests := []struct {
name string
target string
srcPath string
stripPrefix string
expected string
}{
{
name: "target not set",
target: "",
srcPath: "/foo/bar",
stripPrefix: "/foo",
expected: "/bar",
},
{
name: "strip prefix not set",
target: "/hello",
srcPath: "/foo/bar",
stripPrefix: "",
expected: "/hello/foo/bar",
},
{
name: "everything set",
target: "hello",
srcPath: "/foo/bar",
stripPrefix: "/foo",
expected: "/hello/bar",
},
}
for _, tc := range tests {
got := resolveKey(tc.target, tc.srcPath, tc.stripPrefix)
if tc.expected != got {
t.Fatalf("%s: expected error: %v, got: %v", tc.name, tc.expected, got)
}
}
}
func TestNormalizePath(t *testing.T) {
tests := []struct {
input string
expected string
}{
{
input: "/path/to/file.txt",
expected: "path/to/file.txt",
},
{
input: "C:\\Users\\username\\Documents\\file.doc",
expected: "C:\\Users\\username\\Documents\\file.doc",
},
{
input: "relative/path/to/file",
expected: "relative/path/to/file",
},
{
input: "file.txt",
expected: "file.txt",
},
{
input: "/root/directory/",
expected: "root/directory/",
},
{
input: "no_slash",
expected: "no_slash",
},
}
for _, tc := range tests {
result := normalizePath(tc.input)
if result != tc.expected {
t.Errorf("Expected: %s, Got: %s", tc.expected, result)
}
}
}
func TestResolveSource(t *testing.T) {
tests := []struct {
sourceDir string
source string
stripPrefix string
expected string
}{
// Test case 1
{
sourceDir: "/home/user/documents",
source: "/home/user/documents/file.txt",
stripPrefix: "output-",
expected: "output-file.txt",
},
// Test case 2
{
sourceDir: "assets",
source: "assets/images/logo.png",
stripPrefix: "",
expected: "images/logo.png",
},
// Test case 3
{
sourceDir: "/var/www/html",
source: "/var/www/html/pages/index.html",
stripPrefix: "web",
expected: "webpages/index.html",
},
// Test case 4
{
sourceDir: "dist",
source: "dist/js/app.js",
stripPrefix: "public",
expected: "publicjs/app.js",
},
}
for _, tc := range tests {
result := resolveSource(tc.sourceDir, tc.source, tc.stripPrefix)
if result != tc.expected {
t.Errorf("Expected: %s, Got: %s", tc.expected, result)
}
}
}