github.com/sandwich-go/boost@v1.3.29/misc/cloud/storage_test.go (about)

     1  package cloud
     2  
     3  import (
     4  	"context"
     5  	. "github.com/smartystreets/goconvey/convey"
     6  	"os"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestCloud(t *testing.T) {
    12  	key := os.Getenv("RELEASE_CLOUD_KEY")
    13  	secret := os.Getenv("RELEASE_CLOUD_SECRET")
    14  	if len(key) == 0 || len(secret) == 0 {
    15  		return
    16  	}
    17  	sb := MustNew(StorageTypeS3, key, secret, "zhongtai", WithRegion("us-east-2"))
    18  
    19  	Convey("put/stat/list/copy object", t, func() {
    20  		str := "test"
    21  		src := "testtesttest"
    22  		err := sb.PutObject(context.Background(), src, strings.NewReader(str), len(str))
    23  		So(err, ShouldBeNil)
    24  
    25  		info, err0 := sb.StatObject(context.Background(), src)
    26  		So(err0, ShouldBeNil)
    27  		t.Log(info)
    28  
    29  		myChan := sb.ListObjects(context.Background(), "test")
    30  		for v := range myChan {
    31  			t.Log(v)
    32  		}
    33  
    34  		dest := "testtesttest_dest"
    35  		err = sb.CopyObject(context.Background(), dest, src)
    36  		So(err, ShouldBeNil)
    37  
    38  		myChan = sb.ListObjects(context.Background(), "test")
    39  		for v := range myChan {
    40  			t.Log(v)
    41  		}
    42  		err = sb.DelObject(context.Background(), src)
    43  		So(err, ShouldBeNil)
    44  		err = sb.DelObject(context.Background(), dest)
    45  		So(err, ShouldBeNil)
    46  	})
    47  
    48  	Convey("resolve", t, func() {
    49  		s, err := sb.ResolveObjectName("https://fsadfdsa.com/zhongtai/ddd")
    50  		So(err, ShouldBeNil)
    51  		t.Log(s)
    52  	})
    53  }