Add ci test with the testify and travis, test the working
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"net/http"
|
||||
@@ -21,6 +22,8 @@ func main() {
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
SecretID: ak,
|
||||
SecretKey: sk,
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
@@ -30,6 +33,7 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
// Case1 Download object into ReadCloser(). the body needs to be closed
|
||||
name := "test/hello.txt"
|
||||
resp, err := c.Object.Get(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
@@ -39,7 +43,26 @@ func main() {
|
||||
resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
|
||||
// range
|
||||
// Case2 Download object to local file. the body needs to be closed
|
||||
fd, err := os.OpenFile("hello.txt", os.O_WRONLY|os.O_CREATE, 0660)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer fd.Close()
|
||||
resp, err = c.Object.Get(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
io.Copy(fd, resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
// Case3 Download object to local file path
|
||||
err = c.Object.GetToFile(context.Background(), name, "hello_1.txt", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Case4 Download object with range header, can used to concurrent download
|
||||
opt := &cos.ObjectGetOptions{
|
||||
ResponseContentType: "text/html",
|
||||
Range: "bytes=0-3",
|
||||
|
||||
@@ -28,6 +28,7 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
// Case1 normal put object
|
||||
name := "test/objectPut.go"
|
||||
f := strings.NewReader("test")
|
||||
|
||||
@@ -36,6 +37,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Case2 put object with the options
|
||||
name = "test/put_option.go"
|
||||
f = strings.NewReader("test xxx")
|
||||
opt := &cos.ObjectPutOptions{
|
||||
@@ -51,4 +53,11 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Case3 put object by local file
|
||||
_, err = c.Object.PutFromFile(context.Background(), name, "./test10M", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user