✨ init project
This commit is contained in:
100
utils/ast/plugin_initialize_v2_test.go
Normal file
100
utils/ast/plugin_initialize_v2_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/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, "initialize", "plugin_biz_v2.go"),
|
||||
PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
|
||||
ImportPath: `"git.echol.cn/loser/lckt/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(a.Path, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
a.Injection(file)
|
||||
err = a.Format(a.Path, 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, "initialize", "plugin_biz_v2.go"),
|
||||
PluginPath: filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "gva", "plugin.go"),
|
||||
ImportPath: `"git.echol.cn/loser/lckt/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(a.Path, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
a.Rollback(file)
|
||||
err = a.Format(a.Path, nil, file)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Rollback() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user