MSP-1388 [+] тесты
This commit is contained in:
1 parent
9bd31bf6c9
commit
42d2dd18ac
22 files changed
+160
-700
No files matched your search
+4
-4
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type LockerRepo interface {
|
||||
Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error)
|
||||
}
|
||||
|
||||
type Locker struct {
|
||||
@@ -18,12 +18,12 @@ type Locker struct {
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
func (l Locker) Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call srv.Lock")
|
||||
return l.repo.Lock(ctx, req)
|
||||
}
|
||||
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call srv.UnLock")
|
||||
return l.repo.UnLock(ctx, req)
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package service
|
||||
|
||||
//
|
||||
// import (
|
||||
// "context"
|
||||
// "strconv"
|
||||
//
|
||||
// "isp-lock-service/entity"
|
||||
//
|
||||
// "github.com/integration-system/isp-kit/log"
|
||||
// "github.com/pkg/errors"
|
||||
// )
|
||||
//
|
||||
// type MessageTransaction interface {
|
||||
// Lock(ctx context.Context, req domain.Request) error
|
||||
// Insert(ctx context.Context, msg entity.Message) error
|
||||
// GetLastVersion(ctx context.Context, id int64) (int64, error)
|
||||
// UpdateById(ctx context.Context, msg entity.Message) error
|
||||
// }
|
||||
//
|
||||
// type MessageTransactionRunner interface {
|
||||
// MessageTransaction(ctx context.Context, tx func(ctx context.Context, tx MessageTransaction) error) error
|
||||
// }
|
||||
//
|
||||
// type Message struct {
|
||||
// logger log.Logger
|
||||
// txRunner MessageTransactionRunner
|
||||
// }
|
||||
//
|
||||
// func NewMessage(logger log.Logger, txRunner MessageTransactionRunner) *Message {
|
||||
// return &Message{
|
||||
// logger: logger,
|
||||
// txRunner: txRunner,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (m Message) Handle(ctx context.Context, msg entity.Message) error {
|
||||
// ctx = log.ToContext(ctx, log.Int("message_id", int(msg.Id)))
|
||||
// err := m.txRunner.MessageTransaction(ctx, func(ctx context.Context, tx MessageTransaction) error {
|
||||
// return m.handle(ctx, msg, tx)
|
||||
// })
|
||||
// if err != nil {
|
||||
// return errors.WithMessage(err, "message transaction")
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// func (m Message) handle(ctx context.Context, msg entity.Message, tx MessageTransaction) error {
|
||||
// err := tx.Lock(ctx, strconv.FormatInt(msg.Id, 10)) //nolint:gomnd
|
||||
// if err != nil {
|
||||
// return errors.WithMessage(err, "lock by id")
|
||||
// }
|
||||
//
|
||||
// lastVersion, err := tx.GetLastVersion(ctx, msg.Id)
|
||||
// if errors.Is(err, entity.ErrMessageNotFound) {
|
||||
// m.logger.Debug(ctx, "message is not found. insert new one")
|
||||
// err = tx.Insert(ctx, msg)
|
||||
// if err != nil {
|
||||
// return errors.WithMessage(err, "insert")
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// if err != nil {
|
||||
// return errors.WithMessage(err, "get last msg version")
|
||||
// }
|
||||
//
|
||||
// if lastVersion < msg.Version {
|
||||
// m.logger.Debug(ctx, "newer message is received. update")
|
||||
// err = tx.UpdateById(ctx, msg)
|
||||
// if err != nil {
|
||||
// return errors.WithMessage(err, "update by id")
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// m.logger.Debug(ctx, "old version. skipping update")
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
@@ -1,52 +0,0 @@
|
||||
package service
|
||||
|
||||
//
|
||||
// import (
|
||||
// "context"
|
||||
//
|
||||
// "isp-lock-service/domain"
|
||||
// "isp-lock-service/entity"
|
||||
//
|
||||
// "github.com/pkg/errors"
|
||||
// )
|
||||
//
|
||||
// type Repo interface {
|
||||
// All(ctx context.Context) ([]entity.Object, error)
|
||||
// Get(ctx context.Context, id int) (*entity.Object, error)
|
||||
// }
|
||||
//
|
||||
// type Object struct {
|
||||
// repo Repo
|
||||
// }
|
||||
//
|
||||
// func NewObject(repo Repo) Object {
|
||||
// return Object{
|
||||
// repo: repo,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (s Object) All(ctx context.Context) ([]domain.Object, error) {
|
||||
// objects, err := s.repo.All(ctx)
|
||||
// if err != nil {
|
||||
// return nil, errors.WithMessage(err, "get all objects")
|
||||
// }
|
||||
// result := make([]domain.Object, 0, len(objects))
|
||||
// for _, object := range objects {
|
||||
// d := domain.Object{
|
||||
// Name: object.Name,
|
||||
// }
|
||||
// result = append(result, d)
|
||||
// }
|
||||
// return result, nil
|
||||
// }
|
||||
//
|
||||
// func (s Object) Get(ctx context.Context, id int) (*domain.Object, error) {
|
||||
// object, err := s.repo.Get(ctx, id)
|
||||
// if err != nil {
|
||||
// return nil, errors.WithMessagef(err, "get object by id %d", id)
|
||||
// }
|
||||
// d := domain.Object{
|
||||
// Name: object.Name,
|
||||
// }
|
||||
// return &d, nil
|
||||
// }
|
||||
Reference in new issue
Block a user