feat: initial commit
This commit is contained in:
43
test/testutil/fake_session_store.go
Normal file
43
test/testutil/fake_session_store.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/paramah/gw_telegram/internal/domain/apperror"
|
||||
"github.com/paramah/gw_telegram/internal/domain/entity"
|
||||
)
|
||||
|
||||
type FakeSessionStore struct {
|
||||
Sessions map[int64]entity.Session
|
||||
GetError error
|
||||
SetCalled bool
|
||||
LastSetSession entity.Session
|
||||
}
|
||||
|
||||
func (f *FakeSessionStore) Get(_ context.Context, userID int64) (entity.Session, error) {
|
||||
if f.GetError != nil {
|
||||
return entity.Session{}, f.GetError
|
||||
}
|
||||
if f.Sessions != nil {
|
||||
if s, ok := f.Sessions[userID]; ok {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
return entity.Session{}, apperror.ErrSessionNotFound
|
||||
}
|
||||
|
||||
func (f *FakeSessionStore) Set(_ context.Context, session entity.Session) error {
|
||||
f.SetCalled = true
|
||||
f.LastSetSession = session
|
||||
if f.Sessions == nil {
|
||||
f.Sessions = make(map[int64]entity.Session)
|
||||
}
|
||||
f.Sessions[session.UserID] = session
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FakeSessionStore) Delete(_ context.Context, userID int64) error {
|
||||
if f.Sessions != nil {
|
||||
delete(f.Sessions, userID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user