init project
This commit is contained in:
29
modules/system/dao/dao.go
Normal file
29
modules/system/dao/dao.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"app/providers/config"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Dao interface {
|
||||
Release(context.Context, int, string) error
|
||||
}
|
||||
|
||||
type DaoImpl struct {
|
||||
Conf *config.Config
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewDao(DB *gorm.DB) Dao {
|
||||
return &DaoImpl{DB: DB}
|
||||
}
|
||||
|
||||
func (c *DaoImpl) Release(ctx context.Context, a int, b string) error {
|
||||
if a == 20 {
|
||||
return errors.New("A cant't be 20 ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
60
modules/system/dao/dao_test.go
Normal file
60
modules/system/dao/dao_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"app/container"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"app/providers/config"
|
||||
_ "app/providers/httpsvc"
|
||||
_ "app/providers/logger"
|
||||
_ "app/providers/mysql"
|
||||
|
||||
"go.uber.org/dig"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Fields struct {
|
||||
dig.In
|
||||
|
||||
Conf *config.Config
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func TestDaoImpl_Release(t *testing.T) {
|
||||
var ff Fields
|
||||
err := container.Container.Invoke(func(f Fields) {
|
||||
ff = f
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
a int
|
||||
b string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields Fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{"1. ", ff, args{context.Background(), 10, "Rogee"}, false},
|
||||
{"2. ", ff, args{context.Background(), 20, "Rogee"}, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := &DaoImpl{
|
||||
Conf: tt.fields.Conf,
|
||||
DB: tt.fields.DB,
|
||||
}
|
||||
if err := c.Release(tt.args.ctx, tt.args.a, tt.args.b); (err != nil) != tt.wantErr {
|
||||
t.Errorf("DaoImpl.Release() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user