lib: Use counterfeiter to mock interfaces in tests (#7375)

This commit is contained in:
Simon Frei
2021-03-03 08:53:50 +01:00
committed by GitHub
parent 7945430e64
commit 3d91f7c975
46 changed files with 8947 additions and 887 deletions
+2 -2
View File
@@ -60,9 +60,9 @@ func benchmarkRequestsTLS(b *testing.B, conn0, conn1 net.Conn) {
func benchmarkRequestsConnPair(b *testing.B, conn0, conn1 net.Conn) {
// Start up Connections on them
c0 := NewConnection(LocalDeviceID, conn0, conn0, testutils.NoopCloser{}, new(fakeModel), &testutils.FakeConnectionInfo{"c0"}, CompressionMetadata)
c0 := NewConnection(LocalDeviceID, conn0, conn0, testutils.NoopCloser{}, new(fakeModel), new(mockedConnectionInfo), CompressionMetadata)
c0.Start()
c1 := NewConnection(LocalDeviceID, conn1, conn1, testutils.NoopCloser{}, new(fakeModel), &testutils.FakeConnectionInfo{"c1"}, CompressionMetadata)
c1 := NewConnection(LocalDeviceID, conn1, conn1, testutils.NoopCloser{}, new(fakeModel), new(mockedConnectionInfo), CompressionMetadata)
c1.Start()
// Satisfy the assertions in the protocol by sending an initial cluster config
-3
View File
@@ -1,8 +1,5 @@
// Copyright (C) 2014 The Protocol Authors.
//go:generate go run ../../proto/scripts/protofmt.go deviceid_test.proto
//go:generate protoc -I ../../ -I . --gogofast_out=. deviceid_test.proto
package protocol
import "testing"
+24 -20
View File
@@ -1,5 +1,5 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: deviceid_test.proto
// source: lib/protocol/deviceid_test.proto
package protocol
@@ -7,6 +7,7 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/syncthing/syncthing/proto/ext"
io "io"
math "math"
math_bits "math/bits"
@@ -24,14 +25,14 @@ var _ = math.Inf
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type TestOldDeviceID struct {
Test []byte `protobuf:"bytes,1,opt,name=test,proto3" json:"test,omitempty"`
Test []byte `protobuf:"bytes,1,opt,name=test,proto3" json:"test" xml:"test"`
}
func (m *TestOldDeviceID) Reset() { *m = TestOldDeviceID{} }
func (m *TestOldDeviceID) String() string { return proto.CompactTextString(m) }
func (*TestOldDeviceID) ProtoMessage() {}
func (*TestOldDeviceID) Descriptor() ([]byte, []int) {
return fileDescriptor_a5b590761a4231d0, []int{0}
return fileDescriptor_f4a75253a19e48a2, []int{0}
}
func (m *TestOldDeviceID) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -61,14 +62,14 @@ func (m *TestOldDeviceID) XXX_DiscardUnknown() {
var xxx_messageInfo_TestOldDeviceID proto.InternalMessageInfo
type TestNewDeviceID struct {
Test DeviceID `protobuf:"bytes,1,opt,name=test,proto3,customtype=DeviceID" json:"test"`
Test DeviceID `protobuf:"bytes,1,opt,name=test,proto3,customtype=DeviceID" json:"test" xml:"test"`
}
func (m *TestNewDeviceID) Reset() { *m = TestNewDeviceID{} }
func (m *TestNewDeviceID) String() string { return proto.CompactTextString(m) }
func (*TestNewDeviceID) ProtoMessage() {}
func (*TestNewDeviceID) Descriptor() ([]byte, []int) {
return fileDescriptor_a5b590761a4231d0, []int{1}
return fileDescriptor_f4a75253a19e48a2, []int{1}
}
func (m *TestNewDeviceID) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -102,22 +103,25 @@ func init() {
proto.RegisterType((*TestNewDeviceID)(nil), "protocol.TestNewDeviceID")
}
func init() { proto.RegisterFile("deviceid_test.proto", fileDescriptor_a5b590761a4231d0) }
func init() { proto.RegisterFile("lib/protocol/deviceid_test.proto", fileDescriptor_f4a75253a19e48a2) }
var fileDescriptor_a5b590761a4231d0 = []byte{
// 182 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x49, 0x2d, 0xcb,
0x4c, 0x4e, 0xcd, 0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
0xe2, 0x00, 0x53, 0xc9, 0xf9, 0x39, 0x52, 0xca, 0x45, 0xa9, 0x05, 0xf9, 0xc5, 0xfa, 0x60, 0x7e,
0x52, 0x69, 0x9a, 0x7e, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0x03, 0x66, 0x41, 0x94, 0x2b, 0xa9, 0x72,
0xf1, 0x87, 0xa4, 0x16, 0x97, 0xf8, 0xe7, 0xa4, 0xb8, 0x80, 0x0d, 0xf3, 0x74, 0x11, 0x12, 0xe2,
0x62, 0x01, 0x99, 0x27, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x66, 0x2b, 0x99, 0x43, 0x94,
0xf9, 0xa5, 0x96, 0xc3, 0x95, 0xa9, 0x20, 0x2b, 0x73, 0x12, 0x38, 0x71, 0x4f, 0x9e, 0xe1, 0xd6,
0x3d, 0x79, 0x0e, 0x98, 0x3c, 0x44, 0xa3, 0x93, 0xc6, 0x89, 0x87, 0x72, 0x0c, 0x17, 0x1e, 0xca,
0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x0c, 0x2f, 0x1e,
0xc9, 0x31, 0x4c, 0x78, 0x2c, 0xc7, 0xb0, 0xe0, 0xb1, 0x1c, 0xe3, 0x85, 0xc7, 0x72, 0x0c, 0x37,
0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0x1d, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x96,
0x3e, 0xc0, 0xd6, 0x00, 0x00, 0x00,
var fileDescriptor_f4a75253a19e48a2 = []byte{
// 237 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0xc9, 0x4c, 0xd2,
0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0x49, 0x2d, 0xcb, 0x4c, 0x4e, 0xcd,
0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x03, 0x0b, 0x0b, 0x71, 0xc0, 0x64, 0xa5, 0x38, 0x53,
0x2b, 0xa0, 0x82, 0x52, 0xca, 0x45, 0xa9, 0x05, 0xf9, 0xc5, 0x10, 0x8d, 0x49, 0xa5, 0x69, 0xfa,
0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xa4, 0x64, 0xcb, 0xc5, 0x1f, 0x92, 0x5a,
0x5c, 0xe2, 0x9f, 0x93, 0xe2, 0x02, 0x36, 0xd7, 0xd3, 0x45, 0x48, 0x8b, 0x8b, 0x05, 0x64, 0xb4,
0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x93, 0xd8, 0xab, 0x7b, 0xf2, 0x60, 0xfe, 0xa7, 0x7b, 0xf2,
0x5c, 0x15, 0xb9, 0x39, 0x56, 0x4a, 0x20, 0x8e, 0x52, 0x10, 0x58, 0x4c, 0x29, 0x10, 0xa2, 0xdd,
0x2f, 0xb5, 0x1c, 0xae, 0xdd, 0x0e, 0x45, 0xbb, 0xd6, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9,
0x73, 0xc0, 0xe4, 0xb1, 0x1b, 0xd7, 0x71, 0x41, 0x85, 0x11, 0x62, 0xa4, 0x93, 0xef, 0x89, 0x87,
0x72, 0x0c, 0x17, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x84,
0xc7, 0x72, 0x0c, 0x0b, 0x1e, 0xcb, 0x31, 0x5e, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43,
0x94, 0x76, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x71, 0x65, 0x5e,
0x72, 0x49, 0x46, 0x66, 0x5e, 0x3a, 0x12, 0x0b, 0x39, 0xb8, 0x92, 0xd8, 0xc0, 0x2c, 0x63, 0x40,
0x00, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x0a, 0x77, 0x43, 0x45, 0x01, 0x00, 0x00,
}
func (m *TestOldDeviceID) Marshal() (dAtA []byte, err error) {
-23
View File
@@ -1,23 +0,0 @@
syntax = "proto3";
package protocol;
import "repos/protobuf/gogoproto/gogo.proto";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.sizer_all) = false;
option (gogoproto.protosizer_all) = true;
option (gogoproto.goproto_enum_stringer_all) = false;
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
message TestOldDeviceID {
bytes test = 1;
}
message TestNewDeviceID {
bytes test = 1 [(gogoproto.customtype) = "DeviceID", (gogoproto.nullable) = false];
}
+490
View File
@@ -0,0 +1,490 @@
// Code generated by counterfeiter. DO NOT EDIT.
package protocol
import (
"net"
"sync"
"time"
)
type mockedConnectionInfo struct {
CryptoStub func() string
cryptoMutex sync.RWMutex
cryptoArgsForCall []struct {
}
cryptoReturns struct {
result1 string
}
cryptoReturnsOnCall map[int]struct {
result1 string
}
EstablishedAtStub func() time.Time
establishedAtMutex sync.RWMutex
establishedAtArgsForCall []struct {
}
establishedAtReturns struct {
result1 time.Time
}
establishedAtReturnsOnCall map[int]struct {
result1 time.Time
}
PriorityStub func() int
priorityMutex sync.RWMutex
priorityArgsForCall []struct {
}
priorityReturns struct {
result1 int
}
priorityReturnsOnCall map[int]struct {
result1 int
}
RemoteAddrStub func() net.Addr
remoteAddrMutex sync.RWMutex
remoteAddrArgsForCall []struct {
}
remoteAddrReturns struct {
result1 net.Addr
}
remoteAddrReturnsOnCall map[int]struct {
result1 net.Addr
}
StringStub func() string
stringMutex sync.RWMutex
stringArgsForCall []struct {
}
stringReturns struct {
result1 string
}
stringReturnsOnCall map[int]struct {
result1 string
}
TransportStub func() string
transportMutex sync.RWMutex
transportArgsForCall []struct {
}
transportReturns struct {
result1 string
}
transportReturnsOnCall map[int]struct {
result1 string
}
TypeStub func() string
typeMutex sync.RWMutex
typeArgsForCall []struct {
}
typeReturns struct {
result1 string
}
typeReturnsOnCall map[int]struct {
result1 string
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *mockedConnectionInfo) Crypto() string {
fake.cryptoMutex.Lock()
ret, specificReturn := fake.cryptoReturnsOnCall[len(fake.cryptoArgsForCall)]
fake.cryptoArgsForCall = append(fake.cryptoArgsForCall, struct {
}{})
stub := fake.CryptoStub
fakeReturns := fake.cryptoReturns
fake.recordInvocation("Crypto", []interface{}{})
fake.cryptoMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) CryptoCallCount() int {
fake.cryptoMutex.RLock()
defer fake.cryptoMutex.RUnlock()
return len(fake.cryptoArgsForCall)
}
func (fake *mockedConnectionInfo) CryptoCalls(stub func() string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = stub
}
func (fake *mockedConnectionInfo) CryptoReturns(result1 string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = nil
fake.cryptoReturns = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) CryptoReturnsOnCall(i int, result1 string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = nil
if fake.cryptoReturnsOnCall == nil {
fake.cryptoReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.cryptoReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) EstablishedAt() time.Time {
fake.establishedAtMutex.Lock()
ret, specificReturn := fake.establishedAtReturnsOnCall[len(fake.establishedAtArgsForCall)]
fake.establishedAtArgsForCall = append(fake.establishedAtArgsForCall, struct {
}{})
stub := fake.EstablishedAtStub
fakeReturns := fake.establishedAtReturns
fake.recordInvocation("EstablishedAt", []interface{}{})
fake.establishedAtMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) EstablishedAtCallCount() int {
fake.establishedAtMutex.RLock()
defer fake.establishedAtMutex.RUnlock()
return len(fake.establishedAtArgsForCall)
}
func (fake *mockedConnectionInfo) EstablishedAtCalls(stub func() time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = stub
}
func (fake *mockedConnectionInfo) EstablishedAtReturns(result1 time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = nil
fake.establishedAtReturns = struct {
result1 time.Time
}{result1}
}
func (fake *mockedConnectionInfo) EstablishedAtReturnsOnCall(i int, result1 time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = nil
if fake.establishedAtReturnsOnCall == nil {
fake.establishedAtReturnsOnCall = make(map[int]struct {
result1 time.Time
})
}
fake.establishedAtReturnsOnCall[i] = struct {
result1 time.Time
}{result1}
}
func (fake *mockedConnectionInfo) Priority() int {
fake.priorityMutex.Lock()
ret, specificReturn := fake.priorityReturnsOnCall[len(fake.priorityArgsForCall)]
fake.priorityArgsForCall = append(fake.priorityArgsForCall, struct {
}{})
stub := fake.PriorityStub
fakeReturns := fake.priorityReturns
fake.recordInvocation("Priority", []interface{}{})
fake.priorityMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) PriorityCallCount() int {
fake.priorityMutex.RLock()
defer fake.priorityMutex.RUnlock()
return len(fake.priorityArgsForCall)
}
func (fake *mockedConnectionInfo) PriorityCalls(stub func() int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = stub
}
func (fake *mockedConnectionInfo) PriorityReturns(result1 int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = nil
fake.priorityReturns = struct {
result1 int
}{result1}
}
func (fake *mockedConnectionInfo) PriorityReturnsOnCall(i int, result1 int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = nil
if fake.priorityReturnsOnCall == nil {
fake.priorityReturnsOnCall = make(map[int]struct {
result1 int
})
}
fake.priorityReturnsOnCall[i] = struct {
result1 int
}{result1}
}
func (fake *mockedConnectionInfo) RemoteAddr() net.Addr {
fake.remoteAddrMutex.Lock()
ret, specificReturn := fake.remoteAddrReturnsOnCall[len(fake.remoteAddrArgsForCall)]
fake.remoteAddrArgsForCall = append(fake.remoteAddrArgsForCall, struct {
}{})
stub := fake.RemoteAddrStub
fakeReturns := fake.remoteAddrReturns
fake.recordInvocation("RemoteAddr", []interface{}{})
fake.remoteAddrMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) RemoteAddrCallCount() int {
fake.remoteAddrMutex.RLock()
defer fake.remoteAddrMutex.RUnlock()
return len(fake.remoteAddrArgsForCall)
}
func (fake *mockedConnectionInfo) RemoteAddrCalls(stub func() net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = stub
}
func (fake *mockedConnectionInfo) RemoteAddrReturns(result1 net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = nil
fake.remoteAddrReturns = struct {
result1 net.Addr
}{result1}
}
func (fake *mockedConnectionInfo) RemoteAddrReturnsOnCall(i int, result1 net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = nil
if fake.remoteAddrReturnsOnCall == nil {
fake.remoteAddrReturnsOnCall = make(map[int]struct {
result1 net.Addr
})
}
fake.remoteAddrReturnsOnCall[i] = struct {
result1 net.Addr
}{result1}
}
func (fake *mockedConnectionInfo) String() string {
fake.stringMutex.Lock()
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
}{})
stub := fake.StringStub
fakeReturns := fake.stringReturns
fake.recordInvocation("String", []interface{}{})
fake.stringMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) StringCallCount() int {
fake.stringMutex.RLock()
defer fake.stringMutex.RUnlock()
return len(fake.stringArgsForCall)
}
func (fake *mockedConnectionInfo) StringCalls(stub func() string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = stub
}
func (fake *mockedConnectionInfo) StringReturns(result1 string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = nil
fake.stringReturns = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) StringReturnsOnCall(i int, result1 string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = nil
if fake.stringReturnsOnCall == nil {
fake.stringReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.stringReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) Transport() string {
fake.transportMutex.Lock()
ret, specificReturn := fake.transportReturnsOnCall[len(fake.transportArgsForCall)]
fake.transportArgsForCall = append(fake.transportArgsForCall, struct {
}{})
stub := fake.TransportStub
fakeReturns := fake.transportReturns
fake.recordInvocation("Transport", []interface{}{})
fake.transportMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) TransportCallCount() int {
fake.transportMutex.RLock()
defer fake.transportMutex.RUnlock()
return len(fake.transportArgsForCall)
}
func (fake *mockedConnectionInfo) TransportCalls(stub func() string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = stub
}
func (fake *mockedConnectionInfo) TransportReturns(result1 string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = nil
fake.transportReturns = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) TransportReturnsOnCall(i int, result1 string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = nil
if fake.transportReturnsOnCall == nil {
fake.transportReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.transportReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) Type() string {
fake.typeMutex.Lock()
ret, specificReturn := fake.typeReturnsOnCall[len(fake.typeArgsForCall)]
fake.typeArgsForCall = append(fake.typeArgsForCall, struct {
}{})
stub := fake.TypeStub
fakeReturns := fake.typeReturns
fake.recordInvocation("Type", []interface{}{})
fake.typeMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *mockedConnectionInfo) TypeCallCount() int {
fake.typeMutex.RLock()
defer fake.typeMutex.RUnlock()
return len(fake.typeArgsForCall)
}
func (fake *mockedConnectionInfo) TypeCalls(stub func() string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = stub
}
func (fake *mockedConnectionInfo) TypeReturns(result1 string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = nil
fake.typeReturns = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) TypeReturnsOnCall(i int, result1 string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = nil
if fake.typeReturnsOnCall == nil {
fake.typeReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.typeReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *mockedConnectionInfo) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.cryptoMutex.RLock()
defer fake.cryptoMutex.RUnlock()
fake.establishedAtMutex.RLock()
defer fake.establishedAtMutex.RUnlock()
fake.priorityMutex.RLock()
defer fake.priorityMutex.RUnlock()
fake.remoteAddrMutex.RLock()
defer fake.remoteAddrMutex.RUnlock()
fake.stringMutex.RLock()
defer fake.stringMutex.RUnlock()
fake.transportMutex.RLock()
defer fake.transportMutex.RUnlock()
fake.typeMutex.RLock()
defer fake.typeMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *mockedConnectionInfo) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
File diff suppressed because it is too large Load Diff
+494
View File
@@ -0,0 +1,494 @@
// Code generated by counterfeiter. DO NOT EDIT.
package mocks
import (
"net"
"sync"
"time"
"github.com/syncthing/syncthing/lib/protocol"
)
type ConnectionInfo struct {
CryptoStub func() string
cryptoMutex sync.RWMutex
cryptoArgsForCall []struct {
}
cryptoReturns struct {
result1 string
}
cryptoReturnsOnCall map[int]struct {
result1 string
}
EstablishedAtStub func() time.Time
establishedAtMutex sync.RWMutex
establishedAtArgsForCall []struct {
}
establishedAtReturns struct {
result1 time.Time
}
establishedAtReturnsOnCall map[int]struct {
result1 time.Time
}
PriorityStub func() int
priorityMutex sync.RWMutex
priorityArgsForCall []struct {
}
priorityReturns struct {
result1 int
}
priorityReturnsOnCall map[int]struct {
result1 int
}
RemoteAddrStub func() net.Addr
remoteAddrMutex sync.RWMutex
remoteAddrArgsForCall []struct {
}
remoteAddrReturns struct {
result1 net.Addr
}
remoteAddrReturnsOnCall map[int]struct {
result1 net.Addr
}
StringStub func() string
stringMutex sync.RWMutex
stringArgsForCall []struct {
}
stringReturns struct {
result1 string
}
stringReturnsOnCall map[int]struct {
result1 string
}
TransportStub func() string
transportMutex sync.RWMutex
transportArgsForCall []struct {
}
transportReturns struct {
result1 string
}
transportReturnsOnCall map[int]struct {
result1 string
}
TypeStub func() string
typeMutex sync.RWMutex
typeArgsForCall []struct {
}
typeReturns struct {
result1 string
}
typeReturnsOnCall map[int]struct {
result1 string
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *ConnectionInfo) Crypto() string {
fake.cryptoMutex.Lock()
ret, specificReturn := fake.cryptoReturnsOnCall[len(fake.cryptoArgsForCall)]
fake.cryptoArgsForCall = append(fake.cryptoArgsForCall, struct {
}{})
stub := fake.CryptoStub
fakeReturns := fake.cryptoReturns
fake.recordInvocation("Crypto", []interface{}{})
fake.cryptoMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) CryptoCallCount() int {
fake.cryptoMutex.RLock()
defer fake.cryptoMutex.RUnlock()
return len(fake.cryptoArgsForCall)
}
func (fake *ConnectionInfo) CryptoCalls(stub func() string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = stub
}
func (fake *ConnectionInfo) CryptoReturns(result1 string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = nil
fake.cryptoReturns = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) CryptoReturnsOnCall(i int, result1 string) {
fake.cryptoMutex.Lock()
defer fake.cryptoMutex.Unlock()
fake.CryptoStub = nil
if fake.cryptoReturnsOnCall == nil {
fake.cryptoReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.cryptoReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) EstablishedAt() time.Time {
fake.establishedAtMutex.Lock()
ret, specificReturn := fake.establishedAtReturnsOnCall[len(fake.establishedAtArgsForCall)]
fake.establishedAtArgsForCall = append(fake.establishedAtArgsForCall, struct {
}{})
stub := fake.EstablishedAtStub
fakeReturns := fake.establishedAtReturns
fake.recordInvocation("EstablishedAt", []interface{}{})
fake.establishedAtMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) EstablishedAtCallCount() int {
fake.establishedAtMutex.RLock()
defer fake.establishedAtMutex.RUnlock()
return len(fake.establishedAtArgsForCall)
}
func (fake *ConnectionInfo) EstablishedAtCalls(stub func() time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = stub
}
func (fake *ConnectionInfo) EstablishedAtReturns(result1 time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = nil
fake.establishedAtReturns = struct {
result1 time.Time
}{result1}
}
func (fake *ConnectionInfo) EstablishedAtReturnsOnCall(i int, result1 time.Time) {
fake.establishedAtMutex.Lock()
defer fake.establishedAtMutex.Unlock()
fake.EstablishedAtStub = nil
if fake.establishedAtReturnsOnCall == nil {
fake.establishedAtReturnsOnCall = make(map[int]struct {
result1 time.Time
})
}
fake.establishedAtReturnsOnCall[i] = struct {
result1 time.Time
}{result1}
}
func (fake *ConnectionInfo) Priority() int {
fake.priorityMutex.Lock()
ret, specificReturn := fake.priorityReturnsOnCall[len(fake.priorityArgsForCall)]
fake.priorityArgsForCall = append(fake.priorityArgsForCall, struct {
}{})
stub := fake.PriorityStub
fakeReturns := fake.priorityReturns
fake.recordInvocation("Priority", []interface{}{})
fake.priorityMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) PriorityCallCount() int {
fake.priorityMutex.RLock()
defer fake.priorityMutex.RUnlock()
return len(fake.priorityArgsForCall)
}
func (fake *ConnectionInfo) PriorityCalls(stub func() int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = stub
}
func (fake *ConnectionInfo) PriorityReturns(result1 int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = nil
fake.priorityReturns = struct {
result1 int
}{result1}
}
func (fake *ConnectionInfo) PriorityReturnsOnCall(i int, result1 int) {
fake.priorityMutex.Lock()
defer fake.priorityMutex.Unlock()
fake.PriorityStub = nil
if fake.priorityReturnsOnCall == nil {
fake.priorityReturnsOnCall = make(map[int]struct {
result1 int
})
}
fake.priorityReturnsOnCall[i] = struct {
result1 int
}{result1}
}
func (fake *ConnectionInfo) RemoteAddr() net.Addr {
fake.remoteAddrMutex.Lock()
ret, specificReturn := fake.remoteAddrReturnsOnCall[len(fake.remoteAddrArgsForCall)]
fake.remoteAddrArgsForCall = append(fake.remoteAddrArgsForCall, struct {
}{})
stub := fake.RemoteAddrStub
fakeReturns := fake.remoteAddrReturns
fake.recordInvocation("RemoteAddr", []interface{}{})
fake.remoteAddrMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) RemoteAddrCallCount() int {
fake.remoteAddrMutex.RLock()
defer fake.remoteAddrMutex.RUnlock()
return len(fake.remoteAddrArgsForCall)
}
func (fake *ConnectionInfo) RemoteAddrCalls(stub func() net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = stub
}
func (fake *ConnectionInfo) RemoteAddrReturns(result1 net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = nil
fake.remoteAddrReturns = struct {
result1 net.Addr
}{result1}
}
func (fake *ConnectionInfo) RemoteAddrReturnsOnCall(i int, result1 net.Addr) {
fake.remoteAddrMutex.Lock()
defer fake.remoteAddrMutex.Unlock()
fake.RemoteAddrStub = nil
if fake.remoteAddrReturnsOnCall == nil {
fake.remoteAddrReturnsOnCall = make(map[int]struct {
result1 net.Addr
})
}
fake.remoteAddrReturnsOnCall[i] = struct {
result1 net.Addr
}{result1}
}
func (fake *ConnectionInfo) String() string {
fake.stringMutex.Lock()
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
}{})
stub := fake.StringStub
fakeReturns := fake.stringReturns
fake.recordInvocation("String", []interface{}{})
fake.stringMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) StringCallCount() int {
fake.stringMutex.RLock()
defer fake.stringMutex.RUnlock()
return len(fake.stringArgsForCall)
}
func (fake *ConnectionInfo) StringCalls(stub func() string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = stub
}
func (fake *ConnectionInfo) StringReturns(result1 string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = nil
fake.stringReturns = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) StringReturnsOnCall(i int, result1 string) {
fake.stringMutex.Lock()
defer fake.stringMutex.Unlock()
fake.StringStub = nil
if fake.stringReturnsOnCall == nil {
fake.stringReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.stringReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) Transport() string {
fake.transportMutex.Lock()
ret, specificReturn := fake.transportReturnsOnCall[len(fake.transportArgsForCall)]
fake.transportArgsForCall = append(fake.transportArgsForCall, struct {
}{})
stub := fake.TransportStub
fakeReturns := fake.transportReturns
fake.recordInvocation("Transport", []interface{}{})
fake.transportMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) TransportCallCount() int {
fake.transportMutex.RLock()
defer fake.transportMutex.RUnlock()
return len(fake.transportArgsForCall)
}
func (fake *ConnectionInfo) TransportCalls(stub func() string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = stub
}
func (fake *ConnectionInfo) TransportReturns(result1 string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = nil
fake.transportReturns = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) TransportReturnsOnCall(i int, result1 string) {
fake.transportMutex.Lock()
defer fake.transportMutex.Unlock()
fake.TransportStub = nil
if fake.transportReturnsOnCall == nil {
fake.transportReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.transportReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) Type() string {
fake.typeMutex.Lock()
ret, specificReturn := fake.typeReturnsOnCall[len(fake.typeArgsForCall)]
fake.typeArgsForCall = append(fake.typeArgsForCall, struct {
}{})
stub := fake.TypeStub
fakeReturns := fake.typeReturns
fake.recordInvocation("Type", []interface{}{})
fake.typeMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *ConnectionInfo) TypeCallCount() int {
fake.typeMutex.RLock()
defer fake.typeMutex.RUnlock()
return len(fake.typeArgsForCall)
}
func (fake *ConnectionInfo) TypeCalls(stub func() string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = stub
}
func (fake *ConnectionInfo) TypeReturns(result1 string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = nil
fake.typeReturns = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) TypeReturnsOnCall(i int, result1 string) {
fake.typeMutex.Lock()
defer fake.typeMutex.Unlock()
fake.TypeStub = nil
if fake.typeReturnsOnCall == nil {
fake.typeReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.typeReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *ConnectionInfo) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.cryptoMutex.RLock()
defer fake.cryptoMutex.RUnlock()
fake.establishedAtMutex.RLock()
defer fake.establishedAtMutex.RUnlock()
fake.priorityMutex.RLock()
defer fake.priorityMutex.RUnlock()
fake.remoteAddrMutex.RLock()
defer fake.remoteAddrMutex.RUnlock()
fake.stringMutex.RLock()
defer fake.stringMutex.RUnlock()
fake.transportMutex.RLock()
defer fake.transportMutex.RUnlock()
fake.typeMutex.RLock()
defer fake.typeMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *ConnectionInfo) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
var _ protocol.ConnectionInfo = new(ConnectionInfo)
+7
View File
@@ -1,5 +1,12 @@
// Copyright (C) 2014 The Protocol Authors.
// Prevents import loop, for internal testing
//go:generate counterfeiter -o mocked_connection_info_test.go --fake-name mockedConnectionInfo . ConnectionInfo
//go:generate go run ../../script/prune_mocks.go -t mocked_connection_info_test.go
//go:generate counterfeiter -o mocks/connection_info.go --fake-name ConnectionInfo . ConnectionInfo
//go:generate counterfeiter -o mocks/connection.go --fake-name Connection . Connection
package protocol
import (
+11 -11
View File
@@ -31,10 +31,10 @@ func TestPing(t *testing.T) {
ar, aw := io.Pipe()
br, bw := io.Pipe()
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c0.Start()
defer closeAndWait(c0, ar, bw)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c1.Start()
defer closeAndWait(c1, ar, bw)
c0.ClusterConfig(ClusterConfig{})
@@ -57,10 +57,10 @@ func TestClose(t *testing.T) {
ar, aw := io.Pipe()
br, bw := io.Pipe()
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c0.Start()
defer closeAndWait(c0, ar, bw)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, &testutils.FakeConnectionInfo{"name"}, CompressionAlways)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionAlways)
c1.Start()
defer closeAndWait(c1, ar, bw)
c0.ClusterConfig(ClusterConfig{})
@@ -102,7 +102,7 @@ func TestCloseOnBlockingSend(t *testing.T) {
m := newTestModel()
rw := testutils.NewBlockingRW()
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c.Start()
defer closeAndWait(c, rw)
@@ -153,10 +153,10 @@ func TestCloseRace(t *testing.T) {
ar, aw := io.Pipe()
br, bw := io.Pipe()
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, &testutils.FakeConnectionInfo{"c0"}, CompressionNever).(wireFormatConnection).Connection.(*rawConnection)
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionNever).(wireFormatConnection).Connection.(*rawConnection)
c0.Start()
defer closeAndWait(c0, ar, bw)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, &testutils.FakeConnectionInfo{"c1"}, CompressionNever)
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionNever)
c1.Start()
defer closeAndWait(c1, ar, bw)
c0.ClusterConfig(ClusterConfig{})
@@ -193,7 +193,7 @@ func TestClusterConfigFirst(t *testing.T) {
m := newTestModel()
rw := testutils.NewBlockingRW()
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c.Start()
defer closeAndWait(c, rw)
@@ -245,7 +245,7 @@ func TestCloseTimeout(t *testing.T) {
m := newTestModel()
rw := testutils.NewBlockingRW()
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c.Start()
defer closeAndWait(c, rw)
@@ -865,7 +865,7 @@ func TestClusterConfigAfterClose(t *testing.T) {
m := newTestModel()
rw := testutils.NewBlockingRW()
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c.Start()
defer closeAndWait(c, rw)
@@ -889,7 +889,7 @@ func TestDispatcherToCloseDeadlock(t *testing.T) {
// the model callbacks (ClusterConfig).
m := newTestModel()
rw := testutils.NewBlockingRW()
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
m.ccFn = func(devID DeviceID, cc ClusterConfig) {
c.Close(errManual)
}