auto_code_package_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package system
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  7. "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  8. )
  9. func Test_autoCodePackage_Create(t *testing.T) {
  10. type args struct {
  11. ctx context.Context
  12. info *request.SysAutoCodePackageCreate
  13. }
  14. tests := []struct {
  15. name string
  16. args args
  17. wantErr bool
  18. }{
  19. {
  20. name: "测试 package",
  21. args: args{
  22. ctx: context.Background(),
  23. info: &request.SysAutoCodePackageCreate{
  24. Template: "package",
  25. PackageName: "gva",
  26. },
  27. },
  28. wantErr: false,
  29. },
  30. {
  31. name: "测试 plugin",
  32. args: args{
  33. ctx: context.Background(),
  34. info: &request.SysAutoCodePackageCreate{
  35. Template: "plugin",
  36. PackageName: "gva",
  37. },
  38. },
  39. wantErr: false,
  40. },
  41. }
  42. for _, tt := range tests {
  43. t.Run(tt.name, func(t *testing.T) {
  44. a := &autoCodePackage{}
  45. if err := a.Create(tt.args.ctx, tt.args.info); (err != nil) != tt.wantErr {
  46. t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
  47. }
  48. })
  49. }
  50. }
  51. func Test_autoCodePackage_templates(t *testing.T) {
  52. type args struct {
  53. ctx context.Context
  54. entity model.SysAutoCodePackage
  55. info request.AutoCode
  56. isPackage bool
  57. }
  58. tests := []struct {
  59. name string
  60. args args
  61. wantCode map[string]string
  62. wantEnter map[string]map[string]string
  63. wantErr bool
  64. }{
  65. {
  66. name: "测试1",
  67. args: args{
  68. ctx: context.Background(),
  69. entity: model.SysAutoCodePackage{
  70. Desc: "描述",
  71. Label: "展示名",
  72. Template: "plugin",
  73. PackageName: "preview",
  74. },
  75. info: request.AutoCode{
  76. Abbreviation: "user",
  77. HumpPackageName: "user",
  78. },
  79. isPackage: false,
  80. },
  81. wantErr: false,
  82. },
  83. }
  84. for _, tt := range tests {
  85. t.Run(tt.name, func(t *testing.T) {
  86. s := &autoCodePackage{}
  87. gotCode, gotEnter, gotCreates, err := s.templates(tt.args.ctx, tt.args.entity, tt.args.info, tt.args.isPackage)
  88. if (err != nil) != tt.wantErr {
  89. t.Errorf("templates() error = %v, wantErr %v", err, tt.wantErr)
  90. return
  91. }
  92. for key, value := range gotCode {
  93. t.Logf("\n")
  94. t.Logf(key)
  95. t.Logf(value)
  96. t.Logf("\n")
  97. }
  98. t.Log(gotCreates)
  99. if !reflect.DeepEqual(gotEnter, tt.wantEnter) {
  100. t.Errorf("templates() gotEnter = %v, want %v", gotEnter, tt.wantEnter)
  101. }
  102. })
  103. }
  104. }