jyfs_rpc_test.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package test
  2. import (
  3. "context"
  4. "log"
  5. "testing"
  6. "time"
  7. "os"
  8. "app.yhyue.com/moapp/jyfs/rpc/filesystem"
  9. "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
  10. "app.yhyue.com/moapp/jyfs/rpc/internal/config"
  11. "github.com/tal-tech/go-zero/core/conf"
  12. "github.com/tal-tech/go-zero/zrpc"
  13. )
  14. var C config.Config
  15. func init() {
  16. conf.MustLoad("./filesystem.yaml", &C)
  17. }
  18. // // 创建域
  19. // func Test_CreateDomain(t *testing.T) {
  20. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  21. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  22. // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
  23. // res, err := FileSystem.CreateDomain(ctx, req)
  24. // log.Println("err ", err)
  25. // log.Println("req ", res)
  26. // }
  27. // // 删除域
  28. // func Test_DeleteDomain(t *testing.T) {
  29. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  30. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  31. // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize"}}
  32. // res, err := FileSystem.DeleteDomain(ctx, req)
  33. // log.Println("err ", err)
  34. // log.Println("req ", res)
  35. // }
  36. // // 更新域
  37. // func Test_UpdateDomainMeta(t *testing.T) {
  38. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  39. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  40. // req := &filesystem.DomainReq{Name: "jy-oss-xzh", MetaFields: []string{"docName", "docSuffix", "docSize", "docPage"}}
  41. // res, err := FileSystem.UpdateDomainMeta(ctx, req)
  42. // log.Println("err ", err)
  43. // log.Println("req ", res)
  44. // }
  45. // // 删除文件
  46. // func Test_DeleteFile(t *testing.T) {
  47. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  48. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  49. // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
  50. // res, err := FileSystem.DeleteFile(ctx, req)
  51. // log.Println("err ", err)
  52. // log.Println("req ", res)
  53. // }
  54. // // 获取文件
  55. // func Test_GetFile(t *testing.T) {
  56. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  57. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  58. // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
  59. // res, err := FileSystem.GetFile(ctx, req)
  60. // log.Println("err ", err)
  61. // log.Println("req ", res)
  62. // }
  63. // // 获取文件元数据
  64. // func Test_GetFileMeta(t *testing.T) {
  65. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  66. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  67. // req := &filesystem.LoadFileReq{Domain: "jy-oss-xzh", FileId: "que.txt"}
  68. // res, err := FileSystem.GetFileMeta(ctx, req)
  69. // log.Println("err ", err)
  70. // log.Println("req ", res)
  71. // }
  72. // // 保存文件
  73. // func Test_SaveFile(t *testing.T) {
  74. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  75. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  76. // file, err := os.Open("./111.txt")
  77. // if err != nil {
  78. // return
  79. // }
  80. // defer file.Close()
  81. // // FileInfo:
  82. // stats, err := file.Stat()
  83. // if err != nil {
  84. // return
  85. // }
  86. // // []byte
  87. // data := make([]byte, stats.Size())
  88. // count, err := file.Read(data)
  89. // if err != nil {
  90. // return
  91. // }
  92. // log.Println(count)
  93. // req := &filesystem.SaveFileReq{
  94. // Domain: "jy-oss-xzh",
  95. // FileId: "111.txt",
  96. // Meta: map[string]string{"docName": "111", "docSuffix": ".txt", "docSize": "1024"},
  97. // RawFileContent: data,
  98. // }
  99. // res, err := FileSystem.SaveFile(ctx, req)
  100. // log.Println("err ", err)
  101. // log.Println("req ", res)
  102. // }
  103. // // 更新文件元数据
  104. // func Test_UpdateFileMeta(t *testing.T) {
  105. // ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  106. // FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  107. // req := &filesystem.UpdateFileMetaReq{
  108. // Domain: "jy-oss-xzh",
  109. // FileId: "que.txt",
  110. // Meta: map[string]string{"docName": "que", "docSuffix": ".txt", "docSize": "2048"},
  111. // }
  112. // res, err := FileSystem.UpdateFileMeta(ctx, req)
  113. // log.Println("err ", err)
  114. // log.Println("req ", res)
  115. // }
  116. // 获取ossUrl
  117. func Test_GetOssUrl(t *testing.T) {
  118. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  119. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  120. req := &filesystem.LoadFileReq{
  121. Domain: "jy-oss-xzh",
  122. FileId: "que.txt",
  123. }
  124. res, err := FileSystem.GetOssUril(ctx, req)
  125. log.Println("err ", err)
  126. log.Println("req ", res)
  127. }