auto_code_package_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package system
  2. import (
  3. "context"
  4. model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  6. "reflect"
  7. "testing"
  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. }
  57. tests := []struct {
  58. name string
  59. args args
  60. wantCode map[string]string
  61. wantEnter map[string]map[string]string
  62. wantErr bool
  63. }{
  64. {
  65. name: "测试1",
  66. args: args{
  67. ctx: context.Background(),
  68. entity: model.SysAutoCodePackage{
  69. Desc: "描述",
  70. Label: "展示名",
  71. Template: "plugin",
  72. PackageName: "preview",
  73. },
  74. info: request.AutoCode{
  75. Abbreviation: "user",
  76. HumpPackageName: "user",
  77. },
  78. },
  79. wantErr: false,
  80. },
  81. }
  82. for _, tt := range tests {
  83. t.Run(tt.name, func(t *testing.T) {
  84. s := &autoCodePackage{}
  85. gotCode, gotEnter, gotCreates, err := s.templates(tt.args.ctx, tt.args.entity, tt.args.info)
  86. if (err != nil) != tt.wantErr {
  87. t.Errorf("templates() error = %v, wantErr %v", err, tt.wantErr)
  88. return
  89. }
  90. for key, value := range gotCode {
  91. t.Logf("\n")
  92. t.Logf(key)
  93. t.Logf(value)
  94. t.Logf("\n")
  95. }
  96. t.Log(gotCreates)
  97. if !reflect.DeepEqual(gotEnter, tt.wantEnter) {
  98. t.Errorf("templates() gotEnter = %v, want %v", gotEnter, tt.wantEnter)
  99. }
  100. })
  101. }
  102. }