like malachite (atproto-lastfm-importer) but in go and bluer
go
spotify
tealfm
lastfm
atproto
1package atproto
2
3import (
4 "sync"
5 "time"
6)
7
8type mockKVStore struct {
9 mu sync.Mutex
10 data map[string]int
11 gets [][]string
12 incrs []map[string]int
13}
14
15func (m *mockKVStore) GetMulti(keys []string) (map[string]int, error) {
16 m.mu.Lock()
17 defer m.mu.Unlock()
18 m.gets = append(m.gets, keys)
19 result := make(map[string]int)
20 for _, k := range keys {
21 result[k] = m.data[k]
22 }
23 return result, nil
24}
25
26func (m *mockKVStore) IncrByMulti(counts map[string]int) error {
27 m.mu.Lock()
28 defer m.mu.Unlock()
29 m.incrs = append(m.incrs, counts)
30 for k, v := range counts {
31 m.data[k] += v
32 }
33 return nil
34}
35
36type mockClock struct {
37 mu sync.Mutex
38 now time.Time
39 nows []time.Time
40}
41
42func (m *mockClock) Now() time.Time {
43 m.mu.Lock()
44 defer m.mu.Unlock()
45 m.nows = append(m.nows, m.now)
46 return m.now
47}
48
49type mockKVStoreWithErr struct {
50 Data map[string]int
51 Err error
52}
53
54func (m *mockKVStoreWithErr) GetMulti(keys []string) (map[string]int, error) {
55 return nil, m.Err
56}
57
58func (m *mockKVStoreWithErr) IncrByMulti(counts map[string]int) error {
59 return m.Err
60}
61
62type netError struct {
63 timeout bool
64 temporary bool
65}
66
67func (e *netError) Error() string { return "net error" }
68func (e *netError) Timeout() bool { return e.timeout }
69func (e *netError) Temporary() bool { return e.temporary }