2
0

plugin_initialize_v2_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package ast
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "path/filepath"
  5. "testing"
  6. )
  7. func TestPluginInitialize_Injection(t *testing.T) {
  8. type fields struct {
  9. Type Type
  10. Path string
  11. PluginPath string
  12. ImportPath string
  13. }
  14. tests := []struct {
  15. name string
  16. fields fields
  17. wantErr bool
  18. }{
  19. {
  20. name: "测试 Gva插件 注册注入",
  21. fields: fields{
  22. Type: TypePluginInitializeV2,
  23. Path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "plugin_biz_v2.go"),
  24. PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
  25. ImportPath: `"github.com/flipped-aurora/gin-vue-admin/server/plugin/gva"`,
  26. },
  27. wantErr: false,
  28. },
  29. }
  30. for _, tt := range tests {
  31. t.Run(tt.name, func(t *testing.T) {
  32. a := PluginInitializeV2{
  33. Type: tt.fields.Type,
  34. Path: tt.fields.Path,
  35. PluginPath: tt.fields.PluginPath,
  36. ImportPath: tt.fields.ImportPath,
  37. }
  38. file, err := a.Parse(a.Path, nil)
  39. if err != nil {
  40. t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
  41. }
  42. a.Injection(file)
  43. err = a.Format(a.Path, nil, file)
  44. if (err != nil) != tt.wantErr {
  45. t.Errorf("Injection() error = %v, wantErr %v", err, tt.wantErr)
  46. }
  47. })
  48. }
  49. }
  50. func TestPluginInitialize_Rollback(t *testing.T) {
  51. type fields struct {
  52. Type Type
  53. Path string
  54. PluginPath string
  55. ImportPath string
  56. PluginName string
  57. StructName string
  58. PackageName string
  59. }
  60. tests := []struct {
  61. name string
  62. fields fields
  63. wantErr bool
  64. }{
  65. {
  66. name: "测试 Gva插件 回滚",
  67. fields: fields{
  68. Type: TypePluginInitializeV2,
  69. Path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "plugin_biz_v2.go"),
  70. PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
  71. ImportPath: `"github.com/flipped-aurora/gin-vue-admin/server/plugin/gva"`,
  72. },
  73. wantErr: false,
  74. },
  75. }
  76. for _, tt := range tests {
  77. t.Run(tt.name, func(t *testing.T) {
  78. a := PluginInitializeV2{
  79. Type: tt.fields.Type,
  80. Path: tt.fields.Path,
  81. PluginPath: tt.fields.PluginPath,
  82. ImportPath: tt.fields.ImportPath,
  83. StructName: "Plugin",
  84. PackageName: "gva",
  85. }
  86. file, err := a.Parse(a.Path, nil)
  87. if err != nil {
  88. t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
  89. }
  90. a.Rollback(file)
  91. err = a.Format(a.Path, nil, file)
  92. if (err != nil) != tt.wantErr {
  93. t.Errorf("Rollback() error = %v, wantErr %v", err, tt.wantErr)
  94. }
  95. })
  96. }
  97. }