-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathobs_test.go
97 lines (88 loc) · 2.29 KB
/
obs_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
package CloudStore
import (
"bytes"
"fmt"
"io/ioutil"
"obs"
"os"
"testing"
"github.com/astaxie/beego"
)
var Obs *OBS
func init() {
accessKey := beego.AppConfig.String("obs::accessKey")
secretKey := beego.AppConfig.String("obs::secretKey")
bucket := beego.AppConfig.String("obs::bucket")
endpoint := beego.AppConfig.String("obs::endpoint")
domain := beego.AppConfig.String("obs::domain")
Obs, err = NewOBS(accessKey, secretKey, bucket, endpoint, domain)
if err != nil {
panic(err)
}
}
func TestOBS(t *testing.T) {
// upload
t.Log("=====Upload=====", objectSVG, objectSVGGzip)
err = Obs.Upload(objectSVG, objectSVG)
if err != nil {
t.Error(err)
}
err = Obs.Upload(objectSVGGzip, objectSVGGzip, headerGzip, headerSVG)
if err != nil {
t.Error(err)
}
t.Log("=====IsExist=====")
t.Log(objectSVG, "is exist?(Y):", Obs.IsExist(objectSVG) == nil)
t.Log(objectNotExist, "is exist?(N):", Obs.IsExist(objectNotExist) == nil)
t.Log("=====Lists=====")
if files, err := Obs.Lists(objectPrefix); err != nil {
t.Error(err)
} else {
t.Log(fmt.Sprintf("%+v", files))
}
t.Log("=====GetInfo=====")
if info, err := Obs.GetInfo(objectSVG); err != nil {
t.Error(err.Error())
} else {
t.Log(fmt.Sprintf("%+v", info))
}
t.Log("=====Download=====")
if err := Obs.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(Obs.GetSignURL(objectSVG, 1200))
t.Log(Obs.GetSignURL(objectSVGGzip, 1200))
t.Log("========Finished========")
}
func TestOBS_Upload(t *testing.T) {
input := &obs.PutObjectInput{}
input.Bucket = Obs.Bucket
input.Key = "official.html"
b, _ := ioutil.ReadFile(objectHtml)
input.Body = bytes.NewBuffer(b)
_, err := Obs.Client.PutObject(input)
if err != nil {
panic(err)
}
fmt.Printf("Create object:%s successfully!\n", input.Key)
fmt.Println()
fmt.Println(Obs.GetSignURL(input.Key, 3600))
}
func TestOBS_Delete(t *testing.T) {
if err := Obs.Delete(objectSVG, objectSVGGzip, objectHtml, objectHtmlGzip); err != nil {
t.Error(err)
} else {
t.Log("delete success")
}
if files, err := Obs.Lists(objectPrefix); err != nil {
t.Error(err)
} else {
t.Log(fmt.Sprintf("%+v", files))
}
}