forked from TruthHun/CloudStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cos_test.go
84 lines (77 loc) · 1.96 KB
/
cos_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
package CloudStore
import (
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/astaxie/beego"
)
var (
Cos *COS
objectCOS = "cos.go"
)
func init() {
var err error
secretId := beego.AppConfig.String("cos::accessKey")
secretKey := beego.AppConfig.String("cos::secretKey")
bucket := beego.AppConfig.String("cos::bucket")
appId := beego.AppConfig.String("cos::appId")
region := beego.AppConfig.String("cos::region")
domain := beego.AppConfig.String("cos::domain")
Cos, err = NewCOS(secretId, secretKey, bucket, appId, region, domain)
if err != nil {
panic(err)
}
}
func TestCOS(t *testing.T) {
// upload
t.Log("=====Upload=====", objectSVG, objectSVGGzip)
err = Cos.Upload(objectSVG, objectSVG,headerSVG)
if err != nil {
t.Error(err)
}
err = Cos.Upload(objectSVGGzip, objectSVGGzip, headerGzip,headerSVG)
if err != nil {
t.Error(err)
}
t.Log("=====IsExist=====")
t.Log(objectSVG, "is exist?(Y):", Cos.IsExist(objectSVG) == nil)
t.Log(objectNotExist, "is exist?(N):", Cos.IsExist(objectNotExist) == nil)
t.Log("=====Lists=====")
if files, err := Cos.Lists(objectPrefix); err != nil {
t.Error(err)
} else {
t.Log(fmt.Sprintf("%+v", files))
}
t.Log("=====GetInfo=====")
if info, err := Cos.GetInfo(objectSVG); err != nil {
t.Error(err.Error())
} else {
t.Log(fmt.Sprintf("%+v", info))
}
t.Log("=====Download=====")
if err := Cos.Download(objectSVG, objectDownload); err != nil {
t.Error(err)
} else {
t.Log("download success")
b, _ := ioutil.ReadFile(objectDownload)
t.Log("Content:", string(b))
os.Remove(objectDownload)
}
t.Log("====GetSignURL====")
t.Log(Cos.GetSignURL(objectSVG, 120))
t.Log(Cos.GetSignURL(objectSVGGzip, 120))
t.Log("========Finished========")
}
func TestCOS_Delete(t *testing.T) {
if err := Cos.Delete(objectSVG, objectSVGGzip); err != nil {
t.Error(err)
} else {
t.Log("delete success")
}
if files, err := Cos.Lists(objectPrefix); err != nil {
t.Error(err)
} else {
t.Log(fmt.Sprintf("%+v", files))
}
}