-
Notifications
You must be signed in to change notification settings - Fork 255
/
Copy pathcp_test.go
79 lines (69 loc) · 1.32 KB
/
cp_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
package command
import (
"io"
"os"
"testing"
"gotest.tools/v3/assert"
)
func TestGuessContentType(t *testing.T) {
t.Parallel()
testcases := []struct {
filename string
content string
expectedContentType string
}{
{
filename: "*.pdf",
expectedContentType: "application/pdf",
},
{
filename: "*.css",
expectedContentType: "text/css; charset=utf-8",
},
{
filename: "index",
content: `
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Hello, World! I am s5cmd :)</p>
</body>
</html>
`,
expectedContentType: "text/html; charset=utf-8",
},
// check file extension first without checking the content
{
filename: "index*.txt",
content: `
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Hello, World! I am s5cmd :)</p>
</body>
</html>
`,
expectedContentType: "text/plain; charset=utf-8",
},
}
for _, tc := range testcases {
tc := tc
f, err := os.CreateTemp("", tc.filename)
if err != nil {
t.Error(err)
}
if tc.content != "" {
f.WriteString(tc.content)
f.Seek(0, io.SeekStart)
}
assert.Equal(t, tc.expectedContentType, guessContentType(f))
f.Close()
os.Remove(f.Name())
}
}