diff --git a/bucket_inventory.go b/bucket_inventory.go
index 17ed781..dd3f88e 100644
--- a/bucket_inventory.go
+++ b/bucket_inventory.go
@@ -22,7 +22,6 @@ type BucketInventoryFilter struct {
// BucketInventoryOptionalFields ...
type BucketInventoryOptionalFields struct {
- XMLName xml.Name `xml:"OptionalFields,omitempty"`
BucketInventoryFields []string `xml:"Field,omitempty"`
}
@@ -33,12 +32,11 @@ type BucketInventorySchedule struct {
// BucketInventoryEncryption ...
type BucketInventoryEncryption struct {
- XMLName xml.Name `xml:"Encryption"`
- SSECOS string `xml:"SSE-COS,omitempty"`
+ SSECOS string `xml:"SSE-COS"`
}
-// BucketInventoryDestinationContent ...
-type BucketInventoryDestinationContent struct {
+// BucketInventoryDestination ...
+type BucketInventoryDestination struct {
Bucket string `xml:"Bucket"`
AccountId string `xml:"AccountId,omitempty"`
Prefix string `xml:"Prefix,omitempty"`
@@ -46,12 +44,6 @@ type BucketInventoryDestinationContent struct {
Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"`
}
-// BucketInventoryDestination ...
-type BucketInventoryDestination struct {
- XMLName xml.Name `xml:"Destination"`
- BucketDestination *BucketInventoryDestinationContent `xml:"COSBucketDestination"`
-}
-
// BucketPutInventoryOptions ...
type BucketPutInventoryOptions struct {
XMLName xml.Name `xml:"InventoryConfiguration"`
@@ -61,7 +53,7 @@ type BucketPutInventoryOptions struct {
Filter *BucketInventoryFilter `xml:"Filter,omitempty"`
OptionalFields *BucketInventoryOptionalFields `xml:"OptionalFields,omitempty"`
Schedule *BucketInventorySchedule `xml:"Schedule"`
- Destination *BucketInventoryDestination `xml:"Destination"`
+ Destination *BucketInventoryDestination `xml:"Destination>COSBucketDestination"`
}
// ListBucketInventoryConfigResult result of ListBucketInventoryConfiguration
@@ -74,7 +66,7 @@ type ListBucketInventoryConfigResult struct {
}
// PutBucketInventory https://cloud.tencent.com/document/product/436/33707
-func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
+func (s *BucketService) PutInventory(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
u := fmt.Sprintf("/?inventory&id=%s", id)
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
@@ -88,7 +80,7 @@ func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, o
}
// GetBucketInventory https://cloud.tencent.com/document/product/436/33705
-func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
+func (s *BucketService) GetInventory(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
u := fmt.Sprintf("/?inventory&id=%s", id)
var res BucketGetInventoryResult
sendOpt := sendOptions{
@@ -102,7 +94,7 @@ func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (
}
// DeleteBucketInventory https://cloud.tencent.com/document/product/436/33704
-func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string) (*Response, error) {
+func (s *BucketService) DeleteInventory(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("/?inventory&id=%s", id)
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
@@ -114,7 +106,7 @@ func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string
}
// ListBucketInventoryConfigurations https://cloud.tencent.com/document/product/436/33706
-func (s *BucketService) ListBucketInventoryConfigurationsTest(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
+func (s *BucketService) ListInventoryConfigurations(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
var res ListBucketInventoryConfigResult
var u string
if token == "" {
diff --git a/bucket_inventory_test.go b/bucket_inventory_test.go
new file mode 100644
index 0000000..2921705
--- /dev/null
+++ b/bucket_inventory_test.go
@@ -0,0 +1,292 @@
+package cos
+
+import (
+ "context"
+ "encoding/xml"
+ "fmt"
+ "net/http"
+ "reflect"
+ "testing"
+)
+
+func TestBucketService_PutInventory(t *testing.T) {
+ setup()
+ defer teardown()
+ opt := &BucketPutInventoryOptions{
+ XMLName: xml.Name{Local: "InventoryConfiguration"},
+ ID: "list1",
+ IsEnabled: "True",
+ IncludedObjectVersions: "All",
+ Filter: &BucketInventoryFilter{"myPrefix"},
+ Schedule: &BucketInventorySchedule{"Daily"},
+ Destination: &BucketInventoryDestination{
+ Bucket: "qcs::cos:ap-guangzhou::examplebucket-1250000000",
+ AccountId: "100000000001",
+ Prefix: "list1",
+ Format: "CSV",
+ Encryption: &BucketInventoryEncryption{},
+ },
+ OptionalFields: &BucketInventoryOptionalFields{
+ BucketInventoryFields: []string{
+ "Size",
+ "LastModifiedDate",
+ "ETag",
+ "StorageClass",
+ "IsMultipartUploaded",
+ "ReplicationStatus",
+ },
+ },
+ }
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodPut)
+ vs := values{
+ "inventory": "",
+ "id": "list1",
+ }
+ testFormValues(t, r, vs)
+
+ body := &BucketPutInventoryOptions{}
+ xml.NewDecoder(r.Body).Decode(body)
+ want := opt
+ if !reflect.DeepEqual(want, body) {
+ t.Fatalf("Bucket.PutInventory request\n body: %+v\n, want %+v\n", body, want)
+ }
+ })
+
+ _, err := client.Bucket.PutInventory(context.Background(), "list1", opt)
+ if err != nil {
+ t.Fatalf("Bucket.PutInventory failed, error: %v", err)
+ }
+}
+
+func TestBucketService_GetInventory(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodGet)
+ vs := values{
+ "inventory": "",
+ "id": "list1",
+ }
+ testFormValues(t, r, vs)
+
+ fmt.Fprint(w, `
+ list1
+ True
+
+
+ CSV
+ qcs::cos:ap-guangzhou::examplebucket-1250000000
+ list1
+ 100000000001
+
+
+
+ Daily
+
+
+ myPrefix
+
+ All
+
+ Size
+ LastModifiedDate
+ ETag
+ StorageClass
+ IsMultipartUploaded
+ ReplicationStatus
+
+`)
+ })
+ res, _, err := client.Bucket.GetInventory(context.Background(), "list1")
+ if err != nil {
+ t.Fatalf("Bucket.GetInventory failed, error: %v", err)
+ }
+ want := &BucketGetInventoryResult{
+ XMLName: xml.Name{Local: "InventoryConfiguration"},
+ ID: "list1",
+ IsEnabled: "True",
+ IncludedObjectVersions: "All",
+ Filter: &BucketInventoryFilter{"myPrefix"},
+ Schedule: &BucketInventorySchedule{"Daily"},
+ Destination: &BucketInventoryDestination{
+ Bucket: "qcs::cos:ap-guangzhou::examplebucket-1250000000",
+ AccountId: "100000000001",
+ Prefix: "list1",
+ Format: "CSV",
+ },
+ OptionalFields: &BucketInventoryOptionalFields{
+ BucketInventoryFields: []string{
+ "Size",
+ "LastModifiedDate",
+ "ETag",
+ "StorageClass",
+ "IsMultipartUploaded",
+ "ReplicationStatus",
+ },
+ },
+ }
+
+ if !reflect.DeepEqual(res, want) {
+ t.Errorf("Bucket.GetInventory returned\n%+v, want\n%+v", res, want)
+ }
+}
+
+func TestBucketService_ListInventory(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodGet)
+ vs := values{
+ "inventory": "",
+ }
+ testFormValues(t, r, vs)
+ fmt.Fprint(w, `
+
+ list1
+ True
+
+
+ CSV
+ 1250000000
+ qcs::cos:ap-beijing::examplebucket-1250000000
+ list1
+
+
+
+
+
+
+ Daily
+
+
+ myPrefix
+
+ All
+
+ Size
+ LastModifiedDate
+ ETag
+ StorageClass
+ IsMultipartUpload
+ ReplicationStatus
+
+
+
+ list2
+ True
+
+
+ CSV
+ 1250000000
+ qcs::cos:ap-beijing::examplebucket-1250000000
+ list2
+
+
+
+ Weekly
+
+
+ myPrefix2
+
+ All
+
+ Size
+ LastModifiedDate
+ ETag
+ StorageClass
+
+
+ false
+ ...
+ true
+ 1ueSDFASDF1Tr/XDAFdadEADadf2J/wm36Hy4vbOwM=
+`)
+ })
+
+ res, _, err := client.Bucket.ListInventoryConfigurations(context.Background(), "")
+ if err != nil {
+ t.Fatalf("Bucket.ListInventory failed, error: %v", err)
+ }
+ want := &ListBucketInventoryConfigResult{
+ XMLName: xml.Name{Local: "ListInventoryConfigurationResult"},
+ IsTruncated: true,
+ ContinuationToken: "...",
+ NextContinuationToken: "1ueSDFASDF1Tr/XDAFdadEADadf2J/wm36Hy4vbOwM=",
+ InventoryConfigurations: []BucketListInventoryConfiguartion{
+ BucketListInventoryConfiguartion{
+ XMLName: xml.Name{Local: "InventoryConfiguration"},
+ ID: "list1",
+ IsEnabled: "True",
+ IncludedObjectVersions: "All",
+ Filter: &BucketInventoryFilter{"myPrefix"},
+ Schedule: &BucketInventorySchedule{"Daily"},
+ Destination: &BucketInventoryDestination{
+ Bucket: "qcs::cos:ap-beijing::examplebucket-1250000000",
+ AccountId: "1250000000",
+ Prefix: "list1",
+ Format: "CSV",
+ Encryption: &BucketInventoryEncryption{},
+ },
+ OptionalFields: &BucketInventoryOptionalFields{
+ BucketInventoryFields: []string{
+ "Size",
+ "LastModifiedDate",
+ "ETag",
+ "StorageClass",
+ "IsMultipartUpload",
+ "ReplicationStatus",
+ },
+ },
+ },
+ BucketListInventoryConfiguartion{
+ XMLName: xml.Name{Local: "InventoryConfiguration"},
+ ID: "list2",
+ IsEnabled: "True",
+ IncludedObjectVersions: "All",
+ Filter: &BucketInventoryFilter{"myPrefix2"},
+ Schedule: &BucketInventorySchedule{"Weekly"},
+ Destination: &BucketInventoryDestination{
+ Bucket: "qcs::cos:ap-beijing::examplebucket-1250000000",
+ AccountId: "1250000000",
+ Prefix: "list2",
+ Format: "CSV",
+ },
+ OptionalFields: &BucketInventoryOptionalFields{
+ BucketInventoryFields: []string{
+ "Size",
+ "LastModifiedDate",
+ "ETag",
+ "StorageClass",
+ },
+ },
+ },
+ },
+ }
+ if !reflect.DeepEqual(res, want) {
+ t.Fatalf("Bucket.ListInventory failed, \nwant: %+v\nres: %+v", want, res)
+ }
+}
+
+func TestBucketService_DeleteInventory(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodDelete)
+ vs := values{
+ "inventory": "",
+ "id": "list1",
+ }
+ testFormValues(t, r, vs)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ _, err := client.Bucket.DeleteInventory(context.Background(), "list1")
+ if err != nil {
+ t.Fatalf("Bucket.DeleteInventory returned error: %v", err)
+ }
+}
diff --git a/bucket_logging.go b/bucket_logging.go
index d4ea513..96d51cf 100644
--- a/bucket_logging.go
+++ b/bucket_logging.go
@@ -17,17 +17,14 @@ type BucketLoggingEnabled struct {
// BucketPutLoggingOptions is the options of PutBucketLogging
type BucketPutLoggingOptions struct {
XMLName xml.Name `xml:"BucketLoggingStatus"`
- LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled"`
+ LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled,omitempty"`
}
// BucketGetLoggingResult is the result of GetBucketLogging
-type BucketGetLoggingResult struct {
- XMLName xml.Name `xml:"BucketLoggingStatus"`
- LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled"`
-}
+type BucketGetLoggingResult BucketPutLoggingOptions
// PutBucketLogging https://cloud.tencent.com/document/product/436/17054
-func (s *BucketService) PutBucketLoggingTest(ctx context.Context, opt *BucketPutLoggingOptions) (*Response, error) {
+func (s *BucketService) PutLogging(ctx context.Context, opt *BucketPutLoggingOptions) (*Response, error) {
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?logging",
@@ -39,7 +36,7 @@ func (s *BucketService) PutBucketLoggingTest(ctx context.Context, opt *BucketPut
}
// GetBucketLogging https://cloud.tencent.com/document/product/436/17053
-func (s *BucketService) GetBucketLoggingTest(ctx context.Context) (*BucketGetLoggingResult, *Response, error) {
+func (s *BucketService) GetLogging(ctx context.Context) (*BucketGetLoggingResult, *Response, error) {
var res BucketGetLoggingResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
diff --git a/bucket_logging_test.go b/bucket_logging_test.go
new file mode 100644
index 0000000..ec73603
--- /dev/null
+++ b/bucket_logging_test.go
@@ -0,0 +1,75 @@
+package cos
+
+import (
+ "context"
+ "encoding/xml"
+ "fmt"
+ "net/http"
+ "reflect"
+ "testing"
+)
+
+func TestBucketService_PutLogging(t *testing.T) {
+ setup()
+ defer teardown()
+ opt := &BucketPutLoggingOptions{
+ LoggingEnabled: &BucketLoggingEnabled{
+ TargetBucket: "logs",
+ },
+ }
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodPut)
+ vs := values{
+ "logging": "",
+ }
+ testFormValues(t, r, vs)
+
+ body := &BucketPutLoggingOptions{}
+ xml.NewDecoder(r.Body).Decode(body)
+ want := opt
+ want.XMLName = xml.Name{Local: "BucketLoggingStatus"}
+ if !reflect.DeepEqual(want, body) {
+ t.Fatalf("Bucket.PutLogging request\n body: %+v\n, want %+v\n", body, want)
+ }
+ })
+
+ _, err := client.Bucket.PutLogging(context.Background(), opt)
+ if err != nil {
+ t.Fatalf("Bucket.PutLogging failed, error: %v", err)
+ }
+}
+
+func TestBucketService_GetLogging(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodGet)
+ vs := values{
+ "logging": "",
+ }
+ testFormValues(t, r, vs)
+
+ fmt.Fprint(w, `
+
+ logs
+ mylogs
+
+`)
+ })
+ res, _, err := client.Bucket.GetLogging(context.Background())
+ if err != nil {
+ t.Fatalf("Bucket.GetLogging failed, error: %v", err)
+ }
+ want := &BucketGetLoggingResult{
+ XMLName: xml.Name{Local: "BucketLoggingStatus"},
+ LoggingEnabled: &BucketLoggingEnabled{
+ TargetBucket: "logs",
+ TargetPrefix: "mylogs",
+ },
+ }
+
+ if !reflect.DeepEqual(res, want) {
+ t.Errorf("Bucket.GetLogging returned\n%+v, want\n%+v", res, want)
+ }
+}
diff --git a/bucket_replication.go b/bucket_replication.go
index d0a1a9a..04384aa 100644
--- a/bucket_replication.go
+++ b/bucket_replication.go
@@ -28,11 +28,7 @@ type PutBucketReplicationOptions struct {
}
// GetBucketReplicationResult is the result of GetBucketReplication
-type GetBucketReplicationResult struct {
- XMLName xml.Name `xml:"ReplicationConfiguration"`
- Role string `xml:"Role"`
- Rule []BucketReplicationRule `xml:"Rule"`
-}
+type GetBucketReplicationResult PutBucketReplicationOptions
// PutBucketReplication https://cloud.tencent.com/document/product/436/19223
func (s *BucketService) PutBucketReplication(ctx context.Context, opt *PutBucketReplicationOptions) (*Response, error) {
diff --git a/bucket_replication_test.go b/bucket_replication_test.go
new file mode 100644
index 0000000..6757213
--- /dev/null
+++ b/bucket_replication_test.go
@@ -0,0 +1,115 @@
+package cos
+
+import (
+ "context"
+ "encoding/xml"
+ "fmt"
+ "net/http"
+ "reflect"
+ "testing"
+)
+
+func TestBucketService_PutReplication(t *testing.T) {
+ setup()
+ defer teardown()
+ opt := &PutBucketReplicationOptions{
+ Role: "qcs::cam::uin/100000000001:uin/100000000001",
+ Rule: []BucketReplicationRule{
+ {
+ Status: "Disabled",
+ Prefix: "prefix",
+ Destination: &ReplicationDestination{
+ Bucket: "qcs::cos:ap-beijing-1::examplebucket-1250000000",
+ },
+ },
+ },
+ }
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodPut)
+ vs := values{
+ "replication": "",
+ }
+ testFormValues(t, r, vs)
+
+ body := &PutBucketReplicationOptions{}
+ xml.NewDecoder(r.Body).Decode(body)
+ want := opt
+ want.XMLName = xml.Name{Local: "ReplicationConfiguration"}
+ if !reflect.DeepEqual(want, body) {
+ t.Fatalf("Bucket.PutReplication request\n body: %+v\n, want %+v\n", body, want)
+ }
+ })
+
+ _, err := client.Bucket.PutBucketReplication(context.Background(), opt)
+ if err != nil {
+ t.Fatalf("Bucket.PutLogging failed, error: %v", err)
+ }
+}
+
+func TestBucketService_GetReplication(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodGet)
+ vs := values{
+ "replication": "",
+ }
+ testFormValues(t, r, vs)
+
+ fmt.Fprint(w, `
+ qcs::cam::uin/100000000001:uin/100000000001
+
+ Disabled
+
+ prefix
+
+ qcs::cos:ap-beijing-1::examplebucket-1250000000
+
+
+`)
+
+ })
+ res, _, err := client.Bucket.GetBucketReplication(context.Background())
+ if err != nil {
+ t.Fatalf("Bucket.GetReplication failed, error: %v", err)
+ }
+ want := &GetBucketReplicationResult{
+ XMLName: xml.Name{Local: "ReplicationConfiguration"},
+ Role: "qcs::cam::uin/100000000001:uin/100000000001",
+ Rule: []BucketReplicationRule{
+ {
+ Status: "Disabled",
+ Prefix: "prefix",
+ Destination: &ReplicationDestination{
+ Bucket: "qcs::cos:ap-beijing-1::examplebucket-1250000000",
+ },
+ },
+ },
+ }
+
+ if !reflect.DeepEqual(res, want) {
+ t.Errorf("Bucket.GetBucketReplication\nres %+v\nwant %+v", res.Rule[0].Destination, want.Rule[0].Destination)
+ t.Errorf("Bucket.GetBucketReplication\nres %+v\nwant %+v", res, want)
+ }
+}
+
+func TestBucketService_DeleteReplication(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodDelete)
+ vs := values{
+ "replication": "",
+ }
+ testFormValues(t, r, vs)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ _, err := client.Bucket.DeleteBucketReplication(context.Background())
+ if err != nil {
+ t.Fatalf("Bucket.DeleteBucketReplication returned error: %v", err)
+ }
+}
diff --git a/bucket_version.go b/bucket_version.go
index b74527b..5b50ed4 100644
--- a/bucket_version.go
+++ b/bucket_version.go
@@ -13,10 +13,7 @@ type BucketPutVersionOptions struct {
}
// BucketGetVersionResult is the result of GetBucketVersioning
-type BucketGetVersionResult struct {
- XMLName xml.Name `xml:"VersioningConfiguration"`
- Status string `xml:"Status"`
-}
+type BucketGetVersionResult BucketPutVersionOptions
// PutVersion https://cloud.tencent.com/document/product/436/19889
// Status has Suspended\Enabled
diff --git a/bucket_version_test.go b/bucket_version_test.go
new file mode 100644
index 0000000..370f2c2
--- /dev/null
+++ b/bucket_version_test.go
@@ -0,0 +1,67 @@
+package cos
+
+import (
+ "context"
+ "encoding/xml"
+ "fmt"
+ "net/http"
+ "reflect"
+ "testing"
+)
+
+func TestBucketService_PutVersioning(t *testing.T) {
+ setup()
+ defer teardown()
+ opt := &BucketPutVersionOptions{
+ Status: "Suspended",
+ }
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodPut)
+ vs := values{
+ "versioning": "",
+ }
+ testFormValues(t, r, vs)
+
+ body := &BucketPutVersionOptions{}
+ xml.NewDecoder(r.Body).Decode(body)
+ want := opt
+ want.XMLName = xml.Name{Local: "VersioningConfiguration"}
+ if !reflect.DeepEqual(want, body) {
+ t.Fatalf("Bucket.PutVersioning request\nbody: %+v\nwant %+v\n", body, want)
+ }
+ })
+
+ _, err := client.Bucket.PutVersioning(context.Background(), opt)
+ if err != nil {
+ t.Fatalf("Bucket.PutVersioning failed, error: %v", err)
+ }
+}
+
+func TestBucketService_GetVersioning(t *testing.T) {
+ setup()
+ defer teardown()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ testMethod(t, r, http.MethodGet)
+ vs := values{
+ "versioning": "",
+ }
+ testFormValues(t, r, vs)
+
+ fmt.Fprint(w, `
+ Suspended
+`)
+ })
+ res, _, err := client.Bucket.GetVersioning(context.Background())
+ if err != nil {
+ t.Fatalf("Bucket.GetVersioning failed, error: %v", err)
+ }
+ want := &BucketGetVersionResult{
+ XMLName: xml.Name{Local: "VersioningConfiguration"},
+ Status: "Suspended",
+ }
+
+ if !reflect.DeepEqual(res, want) {
+ t.Errorf("Bucket.GetVersioning returned\n%+v, want\n%+v", res, want)
+ }
+}
diff --git a/costesting/ci_test.go b/costesting/ci_test.go
index 0400e67..37ba06b 100644
--- a/costesting/ci_test.go
+++ b/costesting/ci_test.go
@@ -44,6 +44,16 @@ type CosTestSuite struct {
SepFileName string
}
+// replace
+const (
+ //uin
+ kUin = "100010805041"
+ //Replication Target Region,
+ kRepRegion = "ap-chengdu"
+ //Replication Target Bucket, Version management needs to be turned on beforehand
+ kRepBucket = "cosgosdkreptest"
+)
+
func (s *CosTestSuite) SetupSuite() {
fmt.Println("Set up test")
// init
@@ -52,7 +62,7 @@ func (s *CosTestSuite) SetupSuite() {
// CI client for test interface
// URL like this http://test-1253846586.cos.ap-guangzhou.myqcloud.com
- u := "http://cosgosdktest-1251668577.cos.ap-guangzhou.myqcloud.com"
+ u := "https://cosgosdktest-1259654469.cos.ap-guangzhou.myqcloud.com"
// Get the region
iu, _ := url.Parse(u)
@@ -199,7 +209,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
repOpt := &cos.PutBucketReplicationOptions{
// qcs::cam::uin/[UIN]:uin/[Subaccount]
- Role: "qcs::cam::uin/2779643970:uin/2779643970",
+ Role: "qcs::cam::uin/" + kUin + ":uin/" + kUin,
Rule: []cos.BucketReplicationRule{
{
ID: "1",
@@ -207,7 +217,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
Status: "Enabled",
Destination: &cos.ReplicationDestination{
// qcs::cos:[Region]::[Bucketname-Appid]
- Bucket: "qcs::cos:ap-beijing::alanbj-1251668577",
+ Bucket: "qcs::cos:" + kRepRegion + "::" + kRepBucket + "-" + s.Appid,
},
},
},
@@ -219,7 +229,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
assert.Nil(s.T(), err, "GetBucketReplication Failed")
for _, r := range vr.Rule {
assert.Equal(s.T(), "Enabled", r.Status, "Get Wrong Version status")
- assert.Equal(s.T(), "qcs::cos:ap-beijing::alanbj-1251668577", r.Destination.Bucket, "Get Wrong Version status")
+ assert.Equal(s.T(), "qcs::cos:"+kRepRegion+"::"+kRepBucket+"-"+s.Appid, r.Destination.Bucket, "Get Wrong Version status")
}
_, err = s.Client.Bucket.DeleteBucketReplication(context.Background())
@@ -228,6 +238,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
func (s *CosTestSuite) TestBucketInventory() {
id := "test1"
+ dBucket := "qcs::cos:" + s.Region + "::" + s.Bucket + "-" + s.Appid
opt := &cos.BucketPutInventoryOptions{
ID: id,
// True or False
@@ -246,38 +257,57 @@ func (s *CosTestSuite) TestBucketInventory() {
Frequency: "Daily",
},
Destination: &cos.BucketInventoryDestination{
- BucketDestination: &cos.BucketInventoryDestinationContent{
- Bucket: "qcs::cos:ap-guangzhou::alangz-1251668577",
- Format: "CSV",
- },
+ Bucket: dBucket,
+ Format: "CSV",
},
}
- _, err := s.Client.Bucket.PutBucketInventoryTest(context.Background(), id, opt)
+ _, err := s.Client.Bucket.PutInventory(context.Background(), id, opt)
assert.Nil(s.T(), err, "PutBucketInventory Failed")
- v, _, err := s.Client.Bucket.GetBucketInventoryTest(context.Background(), id)
+ v, _, err := s.Client.Bucket.GetInventory(context.Background(), id)
assert.Nil(s.T(), err, "GetBucketInventory Failed")
assert.Equal(s.T(), "test1", v.ID, "Get Wrong inventory id")
assert.Equal(s.T(), "true", v.IsEnabled, "Get Wrong inventory isenabled")
- assert.Equal(s.T(), "qcs::cos:ap-guangzhou::alangz-1251668577", v.Destination.BucketDestination.Bucket, "Get Wrong inventory isenabled")
+ assert.Equal(s.T(), dBucket, v.Destination.Bucket, "Get Wrong inventory isenabled")
- _, err = s.Client.Bucket.DeleteBucketInventoryTest(context.Background(), id)
+ _, err = s.Client.Bucket.DeleteInventory(context.Background(), id)
assert.Nil(s.T(), err, "DeleteBucketInventory Failed")
-
}
func (s *CosTestSuite) TestBucketLogging() {
+ tBucket := s.Bucket + "-" + s.Appid
opt := &cos.BucketPutLoggingOptions{
LoggingEnabled: &cos.BucketLoggingEnabled{
- // The bucket must same region.
- TargetBucket: "alangz-1251668577",
+ TargetBucket: tBucket,
},
}
- _, err := s.Client.Bucket.PutBucketLoggingTest(context.Background(), opt)
- assert.Nil(s.T(), err, "PutBucketLogging Failed")
- v, _, err := s.Client.Bucket.GetBucketLoggingTest(context.Background())
- assert.Nil(s.T(), err, "GetBucketLogging Failed")
- assert.Equal(s.T(), "alangz-1251668577", v.LoggingEnabled.TargetBucket, "Get Wrong Version status")
+ _, err := s.Client.Bucket.PutLogging(context.Background(), opt)
+ assert.Nil(s.T(), err, "PutLogging Failed")
+ v, _, err := s.Client.Bucket.GetLogging(context.Background())
+ assert.Nil(s.T(), err, "GetLogging Failed")
+ assert.Equal(s.T(), tBucket, v.LoggingEnabled.TargetBucket, "Get Wrong Version status")
+}
+func (s *CosTestSuite) TestBucketTagging() {
+ opt := &cos.BucketPutTaggingOptions{
+ TagSet: []cos.BucketTaggingTag{
+ {
+ Key: "testk1",
+ Value: "testv1",
+ },
+ {
+ Key: "testk2",
+ Value: "testv2",
+ },
+ },
+ }
+ _, err := s.Client.Bucket.PutTagging(context.Background(), opt)
+ assert.Nil(s.T(), err, "Put Tagging Failed")
+ v, _, err := s.Client.Bucket.GetTagging(context.Background())
+ assert.Nil(s.T(), err, "Get Tagging Failed")
+ assert.Equal(s.T(), v.TagSet[0].Key, opt.TagSet[0].Key, "Get Wrong Tag key")
+ assert.Equal(s.T(), v.TagSet[0].Value, opt.TagSet[0].Value, "Get Wrong Tag value")
+ assert.Equal(s.T(), v.TagSet[1].Key, opt.TagSet[1].Key, "Get Wrong Tag key")
+ assert.Equal(s.T(), v.TagSet[1].Value, opt.TagSet[1].Value, "Get Wrong Tag value")
}
func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
@@ -491,7 +521,7 @@ func (s *CosTestSuite) TestPutObjectRestore() {
}
func (s *CosTestSuite) TestCopyObject() {
- u := "http://gosdkcopytest-" + s.Appid + ".cos.ap-beijing-1.myqcloud.com"
+ u := "http://" + kRepBucket + "-" + s.Appid + ".cos." + kRepRegion + ".myqcloud.com"
iu, _ := url.Parse(u)
ib := &cos.BaseURL{BucketURL: iu}
c := cos.NewClient(ib, &http.Client{