jojoliang
5 years ago
9 changed files with 614 additions and 53 deletions
-
24bucket_inventory.go
-
292bucket_inventory_test.go
-
11bucket_logging.go
-
75bucket_logging_test.go
-
6bucket_replication.go
-
115bucket_replication_test.go
-
5bucket_version.go
-
67bucket_version_test.go
-
72costesting/ci_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, `<InventoryConfiguration> |
|||
<Id>list1</Id> |
|||
<IsEnabled>True</IsEnabled> |
|||
<Destination> |
|||
<COSBucketDestination> |
|||
<Format>CSV</Format> |
|||
<Bucket>qcs::cos:ap-guangzhou::examplebucket-1250000000</Bucket> |
|||
<Prefix>list1</Prefix> |
|||
<AccountId>100000000001</AccountId> |
|||
</COSBucketDestination> |
|||
</Destination> |
|||
<Schedule> |
|||
<Frequency>Daily</Frequency> |
|||
</Schedule> |
|||
<Filter> |
|||
<Prefix>myPrefix</Prefix> |
|||
</Filter> |
|||
<IncludedObjectVersions>All</IncludedObjectVersions> |
|||
<OptionalFields> |
|||
<Field>Size</Field> |
|||
<Field>LastModifiedDate</Field> |
|||
<Field>ETag</Field> |
|||
<Field>StorageClass</Field> |
|||
<Field>IsMultipartUploaded</Field> |
|||
<Field>ReplicationStatus</Field> |
|||
</OptionalFields> |
|||
</InventoryConfiguration>`) |
|||
}) |
|||
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, `<ListInventoryConfigurationResult> |
|||
<InventoryConfiguration> |
|||
<Id>list1</Id> |
|||
<IsEnabled>True</IsEnabled> |
|||
<Destination> |
|||
<COSBucketDestination> |
|||
<Format>CSV</Format> |
|||
<AccountId>1250000000</AccountId> |
|||
<Bucket>qcs::cos:ap-beijing::examplebucket-1250000000</Bucket> |
|||
<Prefix>list1</Prefix> |
|||
<Encryption> |
|||
<SSE-COS/> |
|||
</Encryption> |
|||
</COSBucketDestination> |
|||
</Destination> |
|||
<Schedule> |
|||
<Frequency>Daily</Frequency> |
|||
</Schedule> |
|||
<Filter> |
|||
<Prefix>myPrefix</Prefix> |
|||
</Filter> |
|||
<IncludedObjectVersions>All</IncludedObjectVersions> |
|||
<OptionalFields> |
|||
<Field>Size</Field> |
|||
<Field>LastModifiedDate</Field> |
|||
<Field>ETag</Field> |
|||
<Field>StorageClass</Field> |
|||
<Field>IsMultipartUpload</Field> |
|||
<Field>ReplicationStatus</Field> |
|||
</OptionalFields> |
|||
</InventoryConfiguration> |
|||
<InventoryConfiguration> |
|||
<Id>list2</Id> |
|||
<IsEnabled>True</IsEnabled> |
|||
<Destination> |
|||
<COSBucketDestination> |
|||
<Format>CSV</Format> |
|||
<AccountId>1250000000</AccountId> |
|||
<Bucket>qcs::cos:ap-beijing::examplebucket-1250000000</Bucket> |
|||
<Prefix>list2</Prefix> |
|||
</COSBucketDestination> |
|||
</Destination> |
|||
<Schedule> |
|||
<Frequency>Weekly</Frequency> |
|||
</Schedule> |
|||
<Filter> |
|||
<Prefix>myPrefix2</Prefix> |
|||
</Filter> |
|||
<IncludedObjectVersions>All</IncludedObjectVersions> |
|||
<OptionalFields> |
|||
<Field>Size</Field> |
|||
<Field>LastModifiedDate</Field> |
|||
<Field>ETag</Field> |
|||
<Field>StorageClass</Field> |
|||
</OptionalFields> |
|||
</InventoryConfiguration> |
|||
<IsTruncated>false</IsTruncated> |
|||
<ContinuationToken>...</ContinuationToken> |
|||
<IsTruncated>true</IsTruncated> |
|||
<NextContinuationToken>1ueSDFASDF1Tr/XDAFdadEADadf2J/wm36Hy4vbOwM=</NextContinuationToken> |
|||
</ListInventoryConfigurationResult>`) |
|||
}) |
|||
|
|||
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) |
|||
} |
|||
} |
@ -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, `<BucketLoggingStatus> |
|||
<LoggingEnabled> |
|||
<TargetBucket>logs</TargetBucket> |
|||
<TargetPrefix>mylogs</TargetPrefix> |
|||
</LoggingEnabled> |
|||
</BucketLoggingStatus>`) |
|||
}) |
|||
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) |
|||
} |
|||
} |
@ -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, `<ReplicationConfiguration> |
|||
<Role>qcs::cam::uin/100000000001:uin/100000000001</Role> |
|||
<Rule> |
|||
<Status>Disabled</Status> |
|||
<ID></ID> |
|||
<Prefix>prefix</Prefix> |
|||
<Destination> |
|||
<Bucket>qcs::cos:ap-beijing-1::examplebucket-1250000000</Bucket> |
|||
</Destination> |
|||
</Rule> |
|||
</ReplicationConfiguration>`) |
|||
|
|||
}) |
|||
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) |
|||
} |
|||
} |
@ -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, `<VersioningConfiguration> |
|||
<Status>Suspended</Status> |
|||
</VersioningConfiguration>`) |
|||
}) |
|||
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) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue