-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
87 lines (75 loc) · 2.01 KB
/
example_test.go
File metadata and controls
87 lines (75 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package azure
import (
"fmt"
"path"
"strings"
"testing"
)
type FileInfo struct {
FilePath string
filename string
}
func (f *FileInfo) GetName() string {
if path.IsAbs(f.FilePath) {
return path.Dir(f.FilePath)
} else {
paths := strings.Split(f.FilePath, "/")
return paths[len(paths)-1]
}
}
func getFile() []FileInfo {
var fileinfos []FileInfo
//fileinfos = append(fileinfos, FileInfo{FilePath: file10m})
fileinfos = append(fileinfos, FileInfo{FilePath: filePathOne})
fileinfos = append(fileinfos, FileInfo{FilePath: filePathTwo})
return fileinfos
}
var (
filePathOne = "./source/one.txt"
filePathTwo = "./source/two.txt"
filePathStage = "./source/stage.txt"
)
// todo: 考虑使用 mock 进行替换。
func TestUploadFiles(t *testing.T) {
files := getFile()
azure := GetAzure(accountName, accountKey)
container := azure.GetContainerURL("yunkaitest")
for _, file := range files {
success, err := container.GetBlob(file.GetName()).UploadOneFile(file.FilePath)
if err != nil {
panic(err)
}
fmt.Sprintf("上传文件 %v 结果为 %v", file.FilePath, success)
}
}
func TestCreateBlob(t *testing.T) {
azure := GetAzure(accountName, accountKey)
container := azure.GetContainerURL("yunkaitest")
blobURL := container.GetBlob("a/b/c")
success, err := blobURL.UploadOneFile(filePathOne)
if err != nil {
panic(err)
}
fmt.Sprintf("结果为 %v", success)
}
func TestListContainer(t *testing.T) {
azure := GetAzure(accountName, accountKey)
container := azure.GetContainerURL("yunkaitest")
container.ListBlob()
}
func TestDeleteContainerBlob(t *testing.T) {
azure := GetAzure(accountName, accountKey)
container := azure.GetContainerURL("yunkaitest")
blobLists := container.ListBlob()
fmt.Println(blobLists)
_ = blobLists
//for _, blob := range blobLists {
// fmt.Println(blob)
// resp, err := container.GetBlob(blob).BlobURL.Delete(context.Background(), azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
// if err != nil {
// panic(err)
// }
// _ = resp
//}
container.ListBlob()
}