阿里云oss
This commit is contained in:
75
oss_tool/aliyun_oss_test.go
Normal file
75
oss_tool/aliyun_oss_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user