-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
106 lines (91 loc) · 2.26 KB
/
utils_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package discovery
import (
"context"
"testing"
"github.com/Rock-liyi/p2pdb-log/iface"
ipfsCore "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
mock "github.com/ipfs/go-ipfs/core/mock"
core_iface "github.com/ipfs/interface-go-ipfs-core"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
"github.com/stretchr/testify/require"
)
func NewMemoryServices(ctx context.Context, t testing.TB, m mocknet.Mocknet) (core_iface.CoreAPI, func()) {
t.Helper()
core, err := ipfsCore.NewNode(ctx, &ipfsCore.BuildCfg{
Online: true,
Host: mock.MockHostOption(m),
ExtraOpts: map[string]bool{
"pubsub": true,
},
})
require.NoError(t, err)
api, err := coreapi.NewCoreAPI(core)
require.NoError(t, err)
close := func() {
core.Close()
}
return api, close
}
func lastEntry(entries []iface.IPFSLogEntry) iface.IPFSLogEntry {
length := len(entries)
if length > 0 {
return entries[len(entries)-1]
}
return nil
}
func entriesAsStrings(values iface.IPFSLogOrderedEntries) []string {
var foundEntries []string
for _, v := range values.Slice() {
foundEntries = append(foundEntries, string(v.GetPayload()))
}
return foundEntries
}
func getLastEntry(omap iface.IPFSLogOrderedEntries) iface.IPFSLogEntry {
lastKey := omap.Keys()[len(omap.Keys())-1]
return omap.UnsafeGet(lastKey)
}
func minInt(a, b int) int {
if a < b {
return a
}
return b
}
func intPtr(val int) *int {
return &val
}
var bigLogString = `DONE
└─EOF
└─entryC10
└─entryB10
└─entryA10
└─entryC9
└─entryB9
└─entryA9
└─entryC8
└─entryB8
└─entryA8
└─entryC7
└─entryB7
└─entryA7
└─entryC6
└─entryB6
└─entryA6
└─entryC5
└─entryB5
└─entryA5
└─entryC4
└─entryB4
└─entryA4
└─3
└─entryC3
└─entryB3
└─entryA3
└─2
└─entryC2
└─entryB2
└─entryA2
└─1
└─entryC1
└─entryB1
└─entryA1`