-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
session_service.go
51 lines (43 loc) · 2.02 KB
/
session_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mock
import (
"context"
"fmt"
"time"
platform "github.com/influxdata/influxdb/v2"
)
// SessionService is a mock implementation of a retention.SessionService, which
// also makes it a suitable mock to use wherever an platform.SessionService is required.
type SessionService struct {
FindSessionFn func(context.Context, string) (*platform.Session, error)
ExpireSessionFn func(context.Context, string) error
CreateSessionFn func(context.Context, string) (*platform.Session, error)
RenewSessionFn func(ctx context.Context, session *platform.Session, newExpiration time.Time) error
}
// NewSessionService returns a mock SessionService where its methods will return
// zero values.
func NewSessionService() *SessionService {
return &SessionService{
FindSessionFn: func(context.Context, string) (*platform.Session, error) { return nil, fmt.Errorf("mock session") },
CreateSessionFn: func(context.Context, string) (*platform.Session, error) { return nil, fmt.Errorf("mock session") },
ExpireSessionFn: func(context.Context, string) error { return fmt.Errorf("mock session") },
RenewSessionFn: func(ctx context.Context, session *platform.Session, expiredAt time.Time) error {
return fmt.Errorf("mock session")
},
}
}
// FindSession returns the session found at the provided key.
func (s *SessionService) FindSession(ctx context.Context, key string) (*platform.Session, error) {
return s.FindSessionFn(ctx, key)
}
// CreateSession creates a session for a user with the users maximal privileges.
func (s *SessionService) CreateSession(ctx context.Context, user string) (*platform.Session, error) {
return s.CreateSessionFn(ctx, user)
}
// ExpireSession expires the session provided at key.
func (s *SessionService) ExpireSession(ctx context.Context, key string) error {
return s.ExpireSessionFn(ctx, key)
}
// RenewSession extends the expire time to newExpiration.
func (s *SessionService) RenewSession(ctx context.Context, session *platform.Session, expiredAt time.Time) error {
return s.RenewSessionFn(ctx, session, expiredAt)
}