-
Notifications
You must be signed in to change notification settings - Fork 42
/
mock_store.go
48 lines (39 loc) · 938 Bytes
/
mock_store.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
package pirsch
import (
"database/sql"
"github.com/jmoiron/sqlx"
"sync"
"time"
)
// storeMock is a Store implementation for testing purposes.
// It overwrites all functions required for testing using PostgresStore as a base implementation.
type storeMock struct {
PostgresStore
hits []Hit
m sync.Mutex
}
func newTestStore() *storeMock {
return &storeMock{hits: make([]Hit, 0)}
}
func (store *storeMock) NewTx() *sqlx.Tx {
return nil
}
func (store *storeMock) Commit(tx *sqlx.Tx) {
if err := tx.Commit(); err != nil {
panic(err)
}
}
func (store *storeMock) Rollback(tx *sqlx.Tx) {
if err := tx.Rollback(); err != nil {
panic(err)
}
}
func (store *storeMock) SaveHits(hits []Hit) error {
store.m.Lock()
defer store.m.Unlock()
store.hits = append(store.hits, hits...)
return nil
}
func (store *storeMock) Session(tenantID sql.NullInt64, fingerprint string, maxAge time.Time) time.Time {
return time.Now()
}