-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploadhandler_test.go
72 lines (66 loc) · 1.6 KB
/
uploadhandler_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
/*
Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <[email protected]>
*/
package uploadhandler
//lint:file-ignore ST1017 - I prefer Yoda conditions
import (
"path/filepath"
"regexp"
"testing"
)
func Test_urlPath(t *testing.T) {
type args struct {
aURL string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
{" 1", args{"/path/to/file"}, "path"},
{" 2", args{"/path"}, "path"},
{" 3", args{"/"}, ""},
{" 4", args{""}, ""},
{" 5", args{"path/to/file"}, "path"},
{" 6", args{"path"}, "path"},
{" 7", args{"p-a.t_h"}, "p-a.t_h"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := urlPath(tt.args.aURL); got != tt.want {
t.Errorf("urlPath() = %v, want %v", got, tt.want)
}
})
}
} // Test_urlPath()
func TestTUploadHandler_newFilename(t *testing.T) {
dir, _ := filepath.Abs(`./`)
h1 := NewHandler(dir, `Upload`, 0)
re := regexp.MustCompile(dir + `/[a-f0-9]+_.+\.[a-z]+$`)
type args struct {
aFilename string
aExtension string
}
tests := []struct {
name string
fields *TUploadHandler
args args
}{
// TODO: Add test cases.
// {" 0", h1, args{``, ``}},
{" 1", h1, args{`profile.asc`, `.asc`}},
{" 2", h1, args{`profi.jpg`, `.jpg`}},
{" 3", h1, args{`x.mpg`, `.mpg`}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
uh := tt.fields
if got := uh.newFilename(tt.args.aFilename, tt.args.aExtension); !re.Match([]byte(got)) {
t.Errorf("TUploadHandler.newFilename() = '%v'", got)
}
})
}
} // TestTUploadHandler_newFilename()