mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 02:44:02 +03:00
Add antireplay cache mock
This commit is contained in:
@@ -16,7 +16,7 @@ func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
|
|||||||
|
|
||||||
func NewStableBloomFilter(byteSize uint, errorRate float64) mtglib.AntiReplayCache {
|
func NewStableBloomFilter(byteSize uint, errorRate float64) mtglib.AntiReplayCache {
|
||||||
sf := boom.NewDefaultStableBloomFilter(byteSize*8, errorRate) // nolint: gomnd
|
sf := boom.NewDefaultStableBloomFilter(byteSize*8, errorRate) // nolint: gomnd
|
||||||
sf.SetHash(xxhash.New64())
|
sf.SetHash(xxhash.New64())
|
||||||
|
|
||||||
return &stableBloomFilter{
|
return &stableBloomFilter{
|
||||||
filter: *sf,
|
filter: *sf,
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package testlib
|
||||||
|
|
||||||
|
import "github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
type MtglibAntiReplayCacheMock struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MtglibAntiReplayCacheMock) SeenBefore(data []byte) bool {
|
||||||
|
return m.Called(data).Bool(0)
|
||||||
|
}
|
||||||
@@ -13,14 +13,14 @@ type MtglibNetworkMock struct {
|
|||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *MtglibNetworkMock) Dial(network, address string) (net.Conn, error) {
|
func (m *MtglibNetworkMock) Dial(network, address string) (net.Conn, error) {
|
||||||
args := n.Called(network, address)
|
args := m.Called(network, address)
|
||||||
|
|
||||||
return args.Get(0).(net.Conn), args.Error(1)
|
return args.Get(0).(net.Conn), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *MtglibNetworkMock) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
func (m *MtglibNetworkMock) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
args := n.Called(ctx, network, address)
|
args := m.Called(ctx, network, address)
|
||||||
|
|
||||||
return args.Get(0).(net.Conn), args.Error(1)
|
return args.Get(0).(net.Conn), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user