/
mockindexprovider.go
56 lines (40 loc) · 1.1 KB
/
mockindexprovider.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
52
53
54
55
56
package shared_testutil
import (
"context"
"sync"
"github.com/ipfs/go-cid"
provider "github.com/filecoin-project/index-provider"
"github.com/filecoin-project/index-provider/metadata"
)
type MockIndexProvider struct {
provider.Interface
lk sync.Mutex
callback provider.MultihashLister
notifs map[string]metadata.Metadata
}
func NewMockIndexProvider() *MockIndexProvider {
return &MockIndexProvider{
notifs: make(map[string]metadata.Metadata),
}
}
func (m *MockIndexProvider) RegisterMultihashLister(cb provider.MultihashLister) {
m.lk.Lock()
defer m.lk.Unlock()
m.callback = cb
}
func (m *MockIndexProvider) NotifyPut(ctx context.Context, contextID []byte, metadata metadata.Metadata) (cid.Cid, error) {
m.lk.Lock()
defer m.lk.Unlock()
m.notifs[string(contextID)] = metadata
return cid.Undef, nil
}
func (m *MockIndexProvider) NotifyRemove(ctx context.Context, contextID []byte) (cid.Cid, error) {
m.lk.Lock()
defer m.lk.Unlock()
return cid.Undef, nil
}
func (m *MockIndexProvider) GetNotifs() map[string]metadata.Metadata {
m.lk.Lock()
defer m.lk.Unlock()
return m.notifs
}