fix: complete SessionStore stub with all methods
This commit is contained in:
1 parent
8c1ae672e1
commit
59dced4a13
1 file changed
+17
-18
@@ -689,28 +689,27 @@ func TestRouteProfileNoIdentity(t *testing.T) {
|
||||
|
||||
// -- /sessions tests --
|
||||
|
||||
type fakeSessionLister struct {
|
||||
type fakeSessionStore struct {
|
||||
sessions []SessionContext
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeSessionLister) Save(ctx context.Context, s SessionContext) error { return f.err }
|
||||
func (f *fakeSessionLister) Get(ctx context.Context, id string) (*SessionContext, error) {
|
||||
for i := range f.sessions {
|
||||
if f.sessions[i].SessionID == id {
|
||||
return &f.sessions[i], nil
|
||||
}
|
||||
}
|
||||
func (f *fakeSessionStore) Save(ctx context.Context, s SessionContext) error { return f.err }
|
||||
func (f *fakeSessionStore) Get(ctx context.Context, id string) (*SessionContext, error) {
|
||||
for i := range f.sessions { if f.sessions[i].SessionID == id { return &f.sessions[i], nil } }
|
||||
return nil, f.err
|
||||
}
|
||||
func (f *fakeSessionLister) GetByChannel(ctx context.Context, platform, channelID string) ([]SessionContext, error) {
|
||||
return f.sessions, f.err
|
||||
}
|
||||
func (f *fakeSessionLister) Close() error { return nil }
|
||||
func (f *fakeSessionStore) GetByChannel(ctx context.Context, p, c string) ([]SessionContext, error) { return f.sessions, f.err }
|
||||
func (f *fakeSessionStore) Delete(ctx context.Context, id string) error { return f.err }
|
||||
func (f *fakeSessionStore) Touch(ctx context.Context, id string) error { return f.err }
|
||||
func (f *fakeSessionStore) List(ctx context.Context) ([]SessionContext, error) { return f.sessions, f.err }
|
||||
func (f *fakeSessionStore) SaveMessage(ctx context.Context, sid string, msg Message) error { return f.err }
|
||||
func (f *fakeSessionStore) RecentMessages(ctx context.Context, sid string, n int) ([]Message, error) { return nil, f.err }
|
||||
func (f *fakeSessionStore) Close() error { return nil }
|
||||
|
||||
func TestRouteSessionsEmpty(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{}
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{}
|
||||
reply, err := r.Route(context.Background(), Message{Text: "/sessions"})
|
||||
if err != nil {
|
||||
t.Fatalf("Route: %v", err)
|
||||
@@ -733,7 +732,7 @@ func TestRouteSessionsNotConfigured(t *testing.T) {
|
||||
|
||||
func TestRouteSessionsError(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{err: fmt.Errorf("store unavailable")}
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{err: fmt.Errorf("store unavailable")}
|
||||
_, err := r.Route(context.Background(), Message{Text: "/sessions"})
|
||||
if err == nil {
|
||||
t.Error("expected error from Route when List fails")
|
||||
@@ -744,7 +743,7 @@ func TestRouteSessionsError(t *testing.T) {
|
||||
|
||||
func TestRouteResumeNoArg(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{}
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{}
|
||||
reply, err := r.Route(context.Background(), Message{Text: "/resume"})
|
||||
if err != nil {
|
||||
t.Fatalf("Route: %v", err)
|
||||
@@ -767,7 +766,7 @@ func TestRouteResumeNotConfigured(t *testing.T) {
|
||||
|
||||
func TestRouteResumeNoMatch(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{
|
||||
sessions: []SessionContext{
|
||||
{SessionID: "session-1"},
|
||||
},
|
||||
@@ -783,7 +782,7 @@ func TestRouteResumeNoMatch(t *testing.T) {
|
||||
|
||||
func TestRouteResumeAmbiguous(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{
|
||||
sessions: []SessionContext{
|
||||
{SessionID: "abc-123"},
|
||||
{SessionID: "abc-456"},
|
||||
@@ -800,7 +799,7 @@ func TestRouteResumeAmbiguous(t *testing.T) {
|
||||
|
||||
func TestRouteResumeExactMatch(t *testing.T) {
|
||||
r := NewRouter(nil, nil, "test-gw")
|
||||
r.Sessions = &fakeSessionLister{
|
||||
r.Sessions = &fakeSessionLister{fakeSessionStore{fakeSessionStore{
|
||||
sessions: []SessionContext{
|
||||
{SessionID: "abc-123"},
|
||||
{SessionID: "abc-456"},
|
||||
|
||||
Reference in new issue
Block a user