浏览代码

完善测试单元

xuzhiheng 4 年之前
父节点
当前提交
d4df515de8
共有 4 个文件被更改,包括 35 次插入33 次删除
  1. 1 0
      rpc/test/111.txt
  2. 34 8
      rpc/test/jyfs_rpc_test.go
  3. 二进制
      test/.DS_Store
  4. 0 25
      test/createdomain_test.go

+ 1 - 0
rpc/test/111.txt

@@ -0,0 +1 @@
+1111111111111

+ 34 - 8
rpc/test/jyfs_rpc_test.go

@@ -24,7 +24,7 @@ func init() {
 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: "xzh", MetaFields: []string{""}}
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
 	res, err := FileSystem.CreateDomain(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
@@ -34,7 +34,7 @@ func Test_CreateDomain(t *testing.T) {
 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: "xzh", MetaFields: []string{""}}
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
 	res, err := FileSystem.DeleteDomain(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
@@ -44,7 +44,7 @@ func Test_DeleteDomain(t *testing.T) {
 func Test_DeleteFile(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
-	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	req := &filesystem.LoadFileReq{Domain: "xzh", FileId: "que.txt"}
 	res, err := FileSystem.DeleteFile(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
@@ -54,8 +54,8 @@ func Test_DeleteFile(t *testing.T) {
 func Test_GetFile(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
-	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
-	res, err := FileSystem.DeleteDomain(ctx, req)
+	req := &filesystem.LoadFileReq{Domain: "xzh", FileId: "que.txt"}
+	res, err := FileSystem.GetFile(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
 }
@@ -64,7 +64,7 @@ func Test_GetFile(t *testing.T) {
 func Test_GetFileMeta(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
-	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	req := &filesystem.LoadFileReq{Domain: "xzh", FileId: "que.txt"}
 	res, err := FileSystem.GetFileMeta(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
@@ -74,7 +74,29 @@ func Test_GetFileMeta(t *testing.T) {
 func Test_SaveFile(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
-	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	file, err := os.Open("./111.txt")
+	if err != nil {
+		return nil, err
+	}
+	defer file.Close()
+	// FileInfo:
+	stats, err := file.Stat()
+	if err != nil {
+		return nil, err
+	}
+	// []byte
+	data := make([]byte, stats.Size())
+	count, err := file.Read(data)
+	if err != nil {
+		return nil, err
+	}
+	fmt.Println(count)
+	req := &filesystem.SaveFileReq{
+		Domain:         "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)
@@ -84,7 +106,11 @@ func Test_SaveFile(t *testing.T) {
 func Test_UpdateFileMeta(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
-	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	req := &filesystem.UpdateFileMetaReq{
+		Domain: "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)

二进制
test/.DS_Store


+ 0 - 25
test/createdomain_test.go

@@ -1,25 +0,0 @@
-package test
-
-import (
-	"log"
-	"testing"
-
-	"app.yhyue.com/moapp/jyfs/api/internal"
-
-	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
-	"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
-	"github.com/tal-tech/go-zero/zrpc"
-)
-
-var (
-	internal
-	fileSystemConf := config.Config.FileSystemConf
-	FileSystem = filesystemclient.NewFileSystem(zrpc.MustNewClient(fileSystemConf))
-)
-
-// 创建域
-func Test_CreateDomain(t *testing.T) {
-	var req = &filesystem.DomainReq{Name: "xzh"}
-	req := FileSystem.CreateDomain(req)
-	log.Println("req ", req)
-}