master
go 71 lines 1.55 KB
Raw
1 package repo
2
3 import (
4 "context"
5 "errors"
6 "net"
7
8 filestore "github.com/ipfs/boxo/filestore"
9 keystore "github.com/ipfs/boxo/keystore"
10 rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
11
12 config "github.com/ipfs/kubo/config"
13 ma "github.com/multiformats/go-multiaddr"
14 )
15
16 var errTODO = errors.New("TODO: mock repo")
17
18 // Mock is not thread-safe.
19 type Mock struct {
20 C config.Config
21 D Datastore
22 K keystore.Keystore
23 F *filestore.FileManager
24 }
25
26 func (m *Mock) Config() (*config.Config, error) {
27 return &m.C, nil // FIXME threadsafety
28 }
29
30 func (m *Mock) Path() string {
31 return ""
32 }
33
34 func (m *Mock) UserResourceOverrides() (rcmgr.PartialLimitConfig, error) {
35 return rcmgr.PartialLimitConfig{}, nil
36 }
37
38 func (m *Mock) SetConfig(updated *config.Config) error {
39 m.C = *updated // FIXME threadsafety
40 return nil
41 }
42
43 func (m *Mock) BackupConfig(prefix string) (string, error) {
44 return "", errTODO
45 }
46
47 func (m *Mock) SetConfigKey(key string, value any) error {
48 return errTODO
49 }
50
51 func (m *Mock) GetConfigKey(key string) (any, error) {
52 return nil, errTODO
53 }
54
55 func (m *Mock) Datastore() Datastore { return m.D }
56
57 func (m *Mock) GetStorageUsage(_ context.Context) (uint64, error) { return 0, nil }
58
59 func (m *Mock) Close() error { return m.D.Close() }
60
61 func (m *Mock) SetAPIAddr(addr ma.Multiaddr) error { return errTODO }
62
63 func (m *Mock) SetGatewayAddr(addr net.Addr) error { return errTODO }
64
65 func (m *Mock) Keystore() keystore.Keystore { return m.K }
66
67 func (m *Mock) SwarmKey() ([]byte, error) {
68 return nil, nil
69 }
70
71 func (m *Mock) FileManager() *filestore.FileManager { return m.F }