89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package oss_tool
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
accessKeyId = os.Getenv("OSS_ACCESS_KEY_ID")
|
|
accessKeySecret = os.Getenv("OSS_SECRET_ACCESS_KEY")
|
|
region = os.Getenv("OSS_REGION")
|
|
client = &ALiYunOSSClient{
|
|
AccessKeyID: accessKeyId,
|
|
AccessKeySecret: accessKeySecret,
|
|
Region: region,
|
|
}
|
|
)
|
|
|
|
func TestALiYunOSSClient_NewAliYunOSS(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
t.Log(client.ossClient)
|
|
}
|
|
|
|
func TestALiYunOSSClient_GetSignUrl(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
sign, err := client.GetSignUrl("", "test/upload/bizhi1.jpg", 0)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
t.Log(sign)
|
|
}
|
|
|
|
func TestALiYunOSSClient_PutForLocalFile(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
result, err := client.PutForLocalFile("", "test/upload/bizhi2.jpg", "C:\\Users\\Administrator\\Desktop\\壁纸1.jpg")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
t.Log(result)
|
|
}
|
|
|
|
func TestALiYunOSSClient_GetObjectToFile(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = client.GetObjectToFile("", "test/upload/bizhi1.jpg", "D:/bizhi1.jpg")
|
|
if err != nil {
|
|
t.Error(err)
|
|
} else {
|
|
t.Log("成功")
|
|
}
|
|
}
|
|
|
|
func TestALiYunOSSClient_GetObjectToImage(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
img, err := client.GetObjectToImage("", "test/upload/bizhi1.jpg")
|
|
if err != nil {
|
|
t.Error(err)
|
|
} else {
|
|
t.Log(img)
|
|
}
|
|
}
|
|
|
|
func TestALiYunOSSClient_DelObject(t *testing.T) {
|
|
err := client.NewAliYunOSS()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = client.DelObject("", "test/upload/bizhi2.jpg")
|
|
if err != nil {
|
|
t.Error(err)
|
|
} else {
|
|
t.Log("成功")
|
|
}
|
|
}
|