forked from tommyblue/smugmug-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_structs_test.go
106 lines (99 loc) · 2.24 KB
/
json_structs_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
package smugmug
import (
"testing"
"text/template"
)
func Test_albumImage_buildFilename(t *testing.T) {
type fields struct {
FileName string
ImageKey string
ArchivedMD5 string
UploadKey string
}
f := fields{
FileName: "FileNameValue",
ImageKey: "ImageKeyValue",
ArchivedMD5: "ArchivedMD5Value",
UploadKey: "UploadKeyValue",
}
tests := []struct {
name string
fields fields
filenameConf string
want string
wantErr bool
}{
{
name: "filename",
fields: f,
filenameConf: "{{.FileName}}",
want: "FileNameValue",
wantErr: false,
},
{
name: "with apostrophe",
fields: fields{
FileName: "FileName'Value",
},
filenameConf: "{{.FileName}}",
want: "FileName'Value",
wantErr: false,
},
{
name: "empty",
fields: f,
filenameConf: "",
want: "",
wantErr: true,
},
{
name: "wrong",
fields: f,
filenameConf: "{{.WrongKey}}",
want: "",
wantErr: true,
},
{
name: "wrong with extra chars",
fields: f,
filenameConf: "{{.WrongKey}}-",
want: "-",
wantErr: true,
},
{
name: "complex",
fields: f,
filenameConf: "{{.ImageKey}}-{{.FileName}}",
want: "ImageKeyValue-FileNameValue",
wantErr: false,
},
{
name: "all",
fields: f,
filenameConf: "prefix-{{.UploadKey}}/{{.ImageKey}}-{{.FileName}}_{{.ArchivedMD5}}",
want: "prefix-UploadKeyValue/ImageKeyValue-FileNameValue_ArchivedMD5Value",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &albumImage{
FileName: tt.fields.FileName,
ImageKey: tt.fields.ImageKey,
ArchivedMD5: tt.fields.ArchivedMD5,
UploadKey: tt.fields.UploadKey,
}
tmpl, err := template.New("image_filename").Option("missingkey=error").Parse(tt.filenameConf)
if err != nil {
t.Fatal(err)
}
err = a.buildFilename(tmpl)
if (err != nil) != tt.wantErr {
t.Fatalf("error: %v, wantErr %v", err, tt.wantErr)
}
if err == nil && a.Name() != tt.want {
t.Fatalf("want: %s, got: %s", tt.want, a.Name())
}
})
}
}