-
Notifications
You must be signed in to change notification settings - Fork 14
/
bucket_test.go
90 lines (77 loc) · 2.08 KB
/
bucket_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
package bcsgo
import (
"strconv"
"testing"
"time"
)
func randomGlobalBucketName(index int) string {
return ak[:2] + "-sdk-" + strconv.FormatInt(time.Now().Unix(), 10)[5:] + "-" + strconv.Itoa(index)
}
func createBucketTempForTest(t *testing.T) *Bucket {
bucketName := randomGlobalBucketName(1)
bucket := bcs.Bucket(bucketName)
err := bucket.Create()
if err != nil {
t.Error(err)
}
return bucket
}
func deleteBucketForTest(t *testing.T, bucket *Bucket) {
deleteErr := bucket.Delete()
if deleteErr != nil {
t.Error(deleteErr)
}
}
func TestBucketCreateWithACLAndDelete(t *testing.T) {
bucketName := randomGlobalBucketName(1)
newBucket := bcs.Bucket(bucketName)
bucketErr := newBucket.CreateWithACL(ACL_PUBLIC_READ)
if bucketErr != nil {
t.Error(bucketErr)
}
// bucketACL, bucketACLErr := newBucket.GetACL()
// expectedBucketACL := fmt.Sprintf(`{"statements":[{"action":["*"],"effect":"allow","resource":["testsml2\/"],"user":["psp:egg90"]},{"action":["get_object"],"effect":"allow","resource":["%s\/"],"user":["*"]}]}`, bucketName)
// if bucketACLErr != nil {
// fmt.Println(bucketACLErr)
// t.Fail()
// }
// if bucketACL != expectedBucketACL {
// fmt.Println(bucketACL)
// fmt.Println(expectedBucketACL)
// t.Fail()
// }
bucketErr = newBucket.Delete()
if bucketErr != nil {
t.Error(bucketErr)
}
}
func TestBucketCreateWithInvalidName(t *testing.T) {
newBucket := bcs.Bucket("testErrorBucket")
bucketErr := newBucket.Create()
// It shall be failed.
if bucketErr == nil {
t.Error("create bucket with invaid name should failed")
}
}
func TestBucketACL(t *testing.T) {
bucket := createBucketTempForTest(t)
acl, aclErr := bucket.GetACL()
if aclErr != nil {
t.Error(aclErr)
}
if acl == "" {
t.Error("acl string shouldn't be nil")
}
setACLCheckError := func(acl string) {
putErr := bucket.SetACL(acl)
if putErr != nil {
t.Error(putErr)
}
}
setACLCheckError(ACL_PUBLIC_CONTROL)
setACLCheckError(ACL_PUBLIC_READ)
setACLCheckError(ACL_PUBLIC_WRITE)
setACLCheckError(ACL_PUBLIC_READ_WRITE)
setACLCheckError(ACL_PRIVATE)
deleteBucketForTest(t, bucket)
}