-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3pal_test.go
62 lines (49 loc) · 1.32 KB
/
s3pal_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
package main
import (
"fmt"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
"time"
)
func getS3palWithFormat(formatStr string) *S3pal {
awsConfig := AwsConfig{
UploadNameFormat: formatStr,
}
config := S3palConfig{
Aws: awsConfig,
}
s3pal := &S3pal{
Config: config,
}
return s3pal
}
func TestUploadNameF(t *testing.T) {
s3pal := getS3palWithFormat("/blah/%F")
result := s3pal.makeFilename("", "test.jpg")
expected := "/blah/test.jpg"
assert.Equal(t, expected, result)
}
func TestUploadNameTsExt(t *testing.T) {
s3pal := getS3palWithFormat("/ts/%N_%T%E")
result := s3pal.makeFilename("", "cat.jpg")
ts := strconv.FormatInt(time.Now().Unix(), 10)
expected := fmt.Sprintf("/ts/cat_%s.jpg", ts)
assert.Equal(t, expected, result)
}
func TestWithDefaultUploadNameOption(t *testing.T) {
s3pal := getS3palWithFormat("")
now := time.Now()
ts := now.UTC()
day := fmt.Sprintf("%02d", ts.Day())
month := fmt.Sprintf("%02d", ts.Month())
year := fmt.Sprintf("%d", ts.Year())
result := s3pal.makeFilename("", "animals.jpg")
expected := fmt.Sprintf("uploads/%s/%s/%s/animals_%v.jpg", year, month, day, ts.Unix())
assert.Equal(t, expected, result)
}
func TestWithUUID(t *testing.T) {
s3pal := getS3palWithFormat("uuid/%U")
result := s3pal.makeFilename("", "table.jpg")
assert.Equal(t, len(result), 5+36)
}