jyfs_rpc_test.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package test
  2. import (
  3. "context"
  4. "log"
  5. "testing"
  6. "time"
  7. "app.yhyue.com/moapp/jyfs/rpc/filesystem"
  8. "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
  9. "app.yhyue.com/moapp/jyfs/rpc/internal/config"
  10. "github.com/tal-tech/go-zero/core/conf"
  11. "github.com/tal-tech/go-zero/zrpc"
  12. )
  13. var C config.Config
  14. func init() {
  15. conf.MustLoad("./filesystem.yaml", &C)
  16. }
  17. // 创建域
  18. func Test_CreateDomain(t *testing.T) {
  19. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  20. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  21. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  22. res, err := FileSystem.CreateDomain(ctx, req)
  23. log.Println("err ", err)
  24. log.Println("req ", res)
  25. }
  26. // 删除域
  27. func Test_DeleteDomain(t *testing.T) {
  28. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  29. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  30. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  31. res, err := FileSystem.DeleteDomain(ctx, req)
  32. log.Println("err ", err)
  33. log.Println("req ", res)
  34. }
  35. // 删除文件
  36. func Test_DeleteFile(t *testing.T) {
  37. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  38. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  39. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  40. res, err := FileSystem.DeleteFile(ctx, req)
  41. log.Println("err ", err)
  42. log.Println("req ", res)
  43. }
  44. // 获取文件
  45. func Test_GetFile(t *testing.T) {
  46. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  47. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  48. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  49. res, err := FileSystem.DeleteDomain(ctx, req)
  50. log.Println("err ", err)
  51. log.Println("req ", res)
  52. }
  53. // 获取文件元数据
  54. func Test_GetFileMeta(t *testing.T) {
  55. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  56. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  57. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  58. res, err := FileSystem.GetFileMeta(ctx, req)
  59. log.Println("err ", err)
  60. log.Println("req ", res)
  61. }
  62. // 保存文件
  63. func Test_SaveFile(t *testing.T) {
  64. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  65. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  66. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  67. res, err := FileSystem.SaveFile(ctx, req)
  68. log.Println("err ", err)
  69. log.Println("req ", res)
  70. }
  71. // 更新文件元数据
  72. func Test_UpdateFileMeta(t *testing.T) {
  73. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  74. FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
  75. req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
  76. res, err := FileSystem.UpdateFileMeta(ctx, req)
  77. log.Println("err ", err)
  78. log.Println("req ", res)
  79. }