123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package system
- import (
- "context"
- model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
- "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
- "reflect"
- "testing"
- )
- func Test_autoCodePackage_Create(t *testing.T) {
- type args struct {
- ctx context.Context
- info *request.SysAutoCodePackageCreate
- }
- tests := []struct {
- name string
- args args
- wantErr bool
- }{
- {
- name: "测试 package",
- args: args{
- ctx: context.Background(),
- info: &request.SysAutoCodePackageCreate{
- Template: "package",
- PackageName: "gva",
- },
- },
- wantErr: false,
- },
- {
- name: "测试 plugin",
- args: args{
- ctx: context.Background(),
- info: &request.SysAutoCodePackageCreate{
- Template: "plugin",
- PackageName: "gva",
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- a := &autoCodePackage{}
- if err := a.Create(tt.args.ctx, tt.args.info); (err != nil) != tt.wantErr {
- t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
- }
- })
- }
- }
- func Test_autoCodePackage_templates(t *testing.T) {
- type args struct {
- ctx context.Context
- entity model.SysAutoCodePackage
- info request.AutoCode
- }
- tests := []struct {
- name string
- args args
- wantCode map[string]string
- wantEnter map[string]map[string]string
- wantErr bool
- }{
- {
- name: "测试1",
- args: args{
- ctx: context.Background(),
- entity: model.SysAutoCodePackage{
- Desc: "描述",
- Label: "展示名",
- Template: "plugin",
- PackageName: "preview",
- },
- info: request.AutoCode{
- Abbreviation: "user",
- HumpPackageName: "user",
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &autoCodePackage{}
- gotCode, gotEnter, gotCreates, err := s.templates(tt.args.ctx, tt.args.entity, tt.args.info)
- if (err != nil) != tt.wantErr {
- t.Errorf("templates() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- for key, value := range gotCode {
- t.Logf("\n")
- t.Logf(key)
- t.Logf(value)
- t.Logf("\n")
- }
- t.Log(gotCreates)
- if !reflect.DeepEqual(gotEnter, tt.wantEnter) {
- t.Errorf("templates() gotEnter = %v, want %v", gotEnter, tt.wantEnter)
- }
- })
- }
- }
|