123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package test
- import (
- "context"
- "log"
- "testing"
- "time"
- "os"
- "app.yhyue.com/moapp/jyfs/rpc/filesystem"
- "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
- "app.yhyue.com/moapp/jyfs/rpc/internal/config"
- "github.com/tal-tech/go-zero/core/conf"
- "github.com/tal-tech/go-zero/zrpc"
- )
- var C config.Config
- func init() {
- conf.MustLoad("./filesystem.yaml", &C)
- }
- // // 创建域
- // func Test_CreateDomain(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
- // res, err := FileSystem.CreateDomain(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 删除域
- // func Test_DeleteDomain(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
- // res, err := FileSystem.DeleteDomain(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 更新域
- // func Test_UpdateDomainMeta(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize", "docPage"}}
- // res, err := FileSystem.UpdateDomainMeta(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 删除文件
- // func Test_DeleteFile(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
- // res, err := FileSystem.DeleteFile(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 获取文件
- // func Test_GetFile(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
- // res, err := FileSystem.GetFile(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 获取文件元数据
- // func Test_GetFileMeta(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
- // res, err := FileSystem.GetFileMeta(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 保存文件
- // func Test_SaveFile(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // file, err := os.Open("./111.txt")
- // if err != nil {
- // return
- // }
- // defer file.Close()
- // // FileInfo:
- // stats, err := file.Stat()
- // if err != nil {
- // return
- // }
- // // []byte
- // data := make([]byte, stats.Size())
- // count, err := file.Read(data)
- // if err != nil {
- // return
- // }
- // log.Println(count)
- // req := &filesystem.SaveFileReq{
- // Domain: "jy-oss-xzh",
- // FileId: "111.txt",
- // Meta: map[string]string{"docName": "111", "docSuffix": ".txt", "docSize": "1024"},
- // RawFileContent: data,
- // }
- // res, err := FileSystem.SaveFile(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // // 更新文件元数据
- // func Test_UpdateFileMeta(t *testing.T) {
- // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- // req := &filesystem.UpdateFileMetaReq{
- // Domain: "jy-oss-xzh",
- // FileId: "que.txt",
- // Meta: map[string]string{"docName": "que", "docSuffix": ".txt", "docSize": "2048"},
- // }
- // res, err := FileSystem.UpdateFileMeta(ctx, req)
- // log.Println("err ", err)
- // log.Println("req ", res)
- // }
- // 获取ossUrl
- func Test_GetOssUrl(t *testing.T) {
- ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
- FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
- req := &filesystem.LoadFileReq{
- Domain: "jy-oss-xzh",
- FileId: "que.txt",
- }
- res, err := FileSystem.GetOssUril(ctx, req)
- log.Println("err ", err)
- log.Println("req ", res)
- }
|