-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_test.go
75 lines (63 loc) · 1.61 KB
/
main_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
package storage
import (
"context"
"testing"
)
func Test(t *testing.T) {
domain := "http://dux.test"
s3, err := New("local", map[string]string{
// Local
"root": ".",
"path": "upload",
"domain": domain,
// S3
//"region": "",
//"endpoint": "",
//"bucket": "",
//"accessKey": "",
//"secretKey": "",
}, nil)
if err != nil {
t.Error("local init failed:" + err.Error())
}
content := "test"
err = s3.Write(context.Background(), "test.txt", content)
if err != nil {
t.Error("local write failed:" + err.Error())
}
str, err := s3.Read(context.Background(), "test.txt")
if err != nil {
t.Error("local read failed:" + err.Error())
}
if str != content {
t.Error("local read failed: inconsistency of data")
}
publicUrl, err := s3.PublicUrl(context.Background(), "test.txt")
if err != nil {
t.Error("publicUrl failed:" + err.Error())
}
t.Log("publicUrl: " + publicUrl)
if domain+"/test.txt" != publicUrl {
t.Error("publicUrl failed: Link inconsistency")
}
privateUrl, err := s3.PrivateUrl(context.Background(), "test.txt")
if err != nil {
t.Error("privateUrl failed:" + err.Error())
}
t.Log("privateUrl: " + privateUrl)
url, params, err := s3.SignPostUrl(context.Background(), "test2.txt")
if err != nil {
t.Error("privateUrl failed:" + err.Error())
}
t.Log("postUrl: " + url)
t.Log("postParams", params)
url, err = s3.SignPutUrl(context.Background(), "test3.txt")
if err != nil {
t.Error("privateUrl failed:" + err.Error())
}
t.Log("putUrl: " + url)
err = s3.Delete(context.Background(), "test.txt")
if err != nil {
t.Error("local write failed:" + err.Error())
}
}