-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_test.go
52 lines (50 loc) · 1.05 KB
/
image_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
package ordnung
import (
"fmt"
"sync"
"testing"
"time"
)
func TestImage_GenerateNewName(t *testing.T) {
d := time.Now().UTC()
tests := []struct {
name string
image Image
pattern string
names *map[string]int
expected string
}{
{
"YYYY-MM-DD unseen",
Image{"sample.jpg", "", d, true},
"YYYY-MM-DD",
&map[string]int{},
fmt.Sprintf("%v_0000.jpg", d.Format("2006-01-02")),
},
{
"YYYY/MM-DD seen",
Image{"sample.jpg", "", d, true},
"YYYY/MM-DD",
&map[string]int{d.Format("2006/01-02"): 1},
fmt.Sprintf("%v_0002.jpg", d.Format("2006/01-02")),
},
{
"unsupported pattern",
Image{"sample.jpg", "", d, true},
"MM-DD",
&map[string]int{},
fmt.Sprintf("%v_0000.jpg", d.Format("2006-01-02")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.image.GenerateNewName(tt.pattern, tt.names, &sync.Mutex{})
if tt.image.NewName != tt.expected {
t.Errorf(
"expected %v to be the generated name, got %v instead",
tt.expected, tt.image.NewName,
)
}
})
}
}