init
Some checks failed
CI / init (push) Has been cancelled
CI / Frontend node 18.16.0 (push) Has been cancelled
CI / Backend go (1.22) (push) Has been cancelled
CI / devops-test (1.22, 18.16.0) (push) Has been cancelled
CI / release-pr (push) Has been cancelled
CI / release-please (push) Has been cancelled
CI / devops-prod (1.22, 18.x) (push) Has been cancelled
CI / docker (push) Has been cancelled

This commit is contained in:
2026-04-21 16:50:31 +08:00
parent 8ed83dd891
commit 05ee541420
700 changed files with 109511 additions and 26 deletions

View File

@@ -0,0 +1,100 @@
package ast
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"path/filepath"
"testing"
)
func TestPluginInitialize_Injection(t *testing.T) {
type fields struct {
Type Type
Path string
PluginPath string
ImportPath string
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "测试 Gva插件 注册注入",
fields: fields{
Type: TypePluginInitializeV2,
Path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "register.go"),
ImportPath: `"github.com/flipped-aurora/gin-vue-admin/server/plugin/gva"`,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := PluginInitializeV2{
Type: tt.fields.Type,
Path: tt.fields.Path,
PluginPath: tt.fields.PluginPath,
ImportPath: tt.fields.ImportPath,
}
file, err := a.Parse("", nil)
if err != nil {
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
}
a.Injection(file)
err = a.Format("", nil, file)
if (err != nil) != tt.wantErr {
t.Errorf("Injection() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestPluginInitialize_Rollback(t *testing.T) {
type fields struct {
Type Type
Path string
PluginPath string
ImportPath string
PluginName string
StructName string
PackageName string
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "测试 Gva插件 回滚",
fields: fields{
Type: TypePluginInitializeV2,
Path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "register.go"),
ImportPath: `"github.com/flipped-aurora/gin-vue-admin/server/plugin/gva"`,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := PluginInitializeV2{
Type: tt.fields.Type,
Path: tt.fields.Path,
PluginPath: tt.fields.PluginPath,
ImportPath: tt.fields.ImportPath,
StructName: "Plugin",
PackageName: "gva",
}
file, err := a.Parse("", nil)
if err != nil {
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
}
a.Rollback(file)
err = a.Format("", nil, file)
if (err != nil) != tt.wantErr {
t.Errorf("Rollback() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}