-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bucket_test.go
93 lines (83 loc) · 1.81 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
91
92
93
package b2
import (
"os"
"testing"
"log"
"flag"
)
var b2 *B2
var bucketId string
var bucketName string = "5891c9ba3b431ce032169bf1a39abbf2"
func TestMain(m *testing.M) {
flag.Parse()
accountID := os.Getenv("B2_ID")
secretKey := os.Getenv("B2_KEY")
t_b2, err := Authorize(accountID, secretKey)
if err != nil || t_b2 == nil {
log.Print("Unable to Authorize")
}
b2 = t_b2
os.Exit(m.Run())
}
func TestCreateBucket(t *testing.T) {
if b2 == nil {
t.Skip("Preconditions (valid Authorization) not met")
}
bucket, err := b2.CreateBucket(bucketName, "allPrivate")
if err != nil {
t.Fatal(err)
}
log.Printf("%+v", bucket)
bucketId = bucket.BucketID
}
func TestListBuckets(t *testing.T) {
if b2 == nil {
t.Skip("Preconditions (valid Authorization) not met")
}
if len(bucketId) == 0 {
t.Skip("Preconditions (added bucket) not met")
}
buckets, err := b2.ListBuckets()
if err != nil {
t.Fatal(err)
}
log.Printf("%+v", buckets)
contains := false
for _, b := range buckets.Buckets {
if b.BucketID == bucketId {
contains = contains || true
}
}
}
func TestUpdateBucket(t *testing.T) {
if b2 == nil {
t.Skip("Preconditions (valid Authorization) not met")
}
if len(bucketId) == 0 {
t.Skip("Preconditions (added bucket) not met")
}
bucket, err := b2.UpdateBucket(bucketId, "allPublic")
if err != nil {
t.Fatal(err)
}
log.Printf("%+v", bucket)
if bucket.BucketType != "allPublic" {
t.Fatal("Bucket Type not updated to Public")
}
}
func TestDeleteBucket(t *testing.T) {
if b2 == nil {
t.Skip("Preconditions (valid Authorization) not met")
}
if len(bucketId) == 0 {
t.Skip("Preconditions (added bucket) not met")
}
bucket, err := b2.DeleteBucket(bucketId)
if err != nil {
t.Fatal(err)
}
log.Printf("%+v", bucket)
if (bucket.BucketID != bucketId) {
t.Fatal("BucketID mismatch")
}
}