7
0
gaore-common-sdk-go/services/oss/client_test.go

88 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-05-30 18:40:57 +08:00
package oss
import (
2024-07-23 09:22:59 +08:00
"encoding/json"
2024-05-30 18:40:57 +08:00
"os"
"testing"
)
func TestUpload_Put(t *testing.T) {
req := CreatePutOssRequest()
req.BucketName = "image"
file, err := os.ReadFile("test.jpg")
if err != nil {
t.Error(err)
return
}
req.FileStream = file
client, err := NewClient()
resp, err := client.PutOss(req)
if err != nil {
t.Error(err)
return
}
t.Log(resp.Data.Url)
}
func TestUpload_Del(t *testing.T) {
req := CreateDelOssRequest()
req.BucketName = "image"
req.MediaUrl = "https://image.89yoo.com/uploads/549/549e887460a72333c361661683023018.jpeg"
client, err := NewClient()
if err != nil {
t.Error(err)
return
}
resp, err := client.DelOss(req)
if err != nil {
t.Error(err)
return
}
t.Log(resp.Code)
}
func TestCreateInitMultipartUpload(t *testing.T) {
req := CreateInitMultipartUploadRequest()
2024-10-12 15:27:57 +08:00
extInfo := map[string]any{"game_byname": "tech_test_tencent"}
bExtInfo, _ := json.Marshal(extInfo)
req.UploadType = "package"
req.TargetType = "oss"
req.TargetName = "image"
2024-07-23 09:22:59 +08:00
req.FileHash = "51c68615b8d21f9b72b02f48c400cb87"
2024-10-12 15:27:57 +08:00
req.Filepath = "q5-01.zip"
req.ExtInfo = string(bExtInfo)
client, err := NewClient()
if err != nil {
t.Error(err)
return
}
resp, err := client.InitMultipartUpload(req)
if err != nil {
t.Error(err)
return
}
2024-07-23 09:22:59 +08:00
r, err := json.Marshal(resp)
if err != nil {
return
}
t.Log(string(r))
}
func TestClient_GetApkVersion(t *testing.T) {
req := CreateGetApkVersionRequest()
2024-11-19 18:19:02 +08:00
req.Filepath = "uploads/files/package/1f57ac9693f0593fc9073f366b1c1936.zip"
client, err := NewClient()
if err != nil {
t.Error(err)
return
}
resp, err := client.GetApkVersion(req)
if err != nil {
t.Error(err)
return
}
t.Log(resp.Data.VersionCode, resp.Data.VersionName)
}