Merge pull request #53 from agin719/master

add bucket website and domain interface
This commit is contained in:
agin719
2019-12-09 21:09:17 +08:00
committed by GitHub
10 changed files with 635 additions and 3 deletions

View File

@@ -4,9 +4,6 @@ package cos
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/tencentyun/cos-go-sdk-v5"
"io/ioutil"
"math/rand"
"net/http"
@@ -15,6 +12,10 @@ import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/tencentyun/cos-go-sdk-v5"
)
// Define the suite, and absorb the built-in basic suite
@@ -304,6 +305,40 @@ func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
assert.Nil(s.T(), err, "DeleteBucketLifecycle Failed")
}
func (s *CosTestSuite) TestPutGetDeleteWebsite() {
opt := &cos.BucketPutWebsiteOptions{
Index: "index.html",
Error: &cos.ErrorDocument{"index_backup.html"},
RoutingRules: &cos.WebsiteRoutingRules{
[]cos.WebsiteRoutingRule{
{
ConditionErrorCode: "404",
RedirectProtocol: "https",
RedirectReplaceKey: "404.html",
},
{
ConditionPrefix: "docs/",
RedirectProtocol: "https",
RedirectReplaceKeyPrefix: "documents/",
},
},
},
}
_, err := s.Client.Bucket.PutWebsite(context.Background(), opt)
assert.Nil(s.T(), err, "PutBucketWebsite Failed")
res, rsp, err := s.Client.Bucket.GetWebsite(context.Background())
if err != nil && 404 != rsp.StatusCode {
assert.Nil(s.T(), err, "GetBucketWebsite Failed")
}
assert.Equal(s.T(), opt.Index, res.Index, "GetBucketWebsite Failed")
assert.Equal(s.T(), opt.Error, res.Error, "GetBucketWebsite Failed")
assert.Equal(s.T(), opt.RedirectProtocol, res.RedirectProtocol, "GetBucketWebsite Failed")
_, err = s.Client.Bucket.DeleteWebsite(context.Background())
assert.Nil(s.T(), err, "DeleteBucketWebsite Failed")
}
func (s *CosTestSuite) TestListMultipartUploads() {
// Create new upload
name := "test_multipart" + time.Now().Format(time.RFC3339)