From 6dc453caa3719685b3b133ccffeec4311230c5a9 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 17 Oct 2017 21:47:35 +0700 Subject: [PATCH] use mockgen reflect mode This requires a dirty hack to get mockgen to generate mocks for internal packages. --- internal/mocks/flow_control_manager.go | 204 ++++++++++++------------- internal/mocks/gen.go | 5 +- internal/mocks/mockgen_internal.sh | 21 +++ 3 files changed, 124 insertions(+), 106 deletions(-) create mode 100755 internal/mocks/mockgen_internal.sh diff --git a/internal/mocks/flow_control_manager.go b/internal/mocks/flow_control_manager.go index 0aecc9aee..b90d7c03c 100644 --- a/internal/mocks/flow_control_manager.go +++ b/internal/mocks/flow_control_manager.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: ../flowcontrol/interface.go +// Source: github.com/lucas-clemente/quic-go/internal/flowcontrol (interfaces: FlowControlManager) package mocks @@ -7,7 +7,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - "github.com/lucas-clemente/quic-go/internal/flowcontrol" + flowcontrol "github.com/lucas-clemente/quic-go/internal/flowcontrol" handshake "github.com/lucas-clemente/quic-go/internal/handshake" protocol "github.com/lucas-clemente/quic-go/internal/protocol" ) @@ -35,63 +35,9 @@ func (_m *MockFlowControlManager) EXPECT() *MockFlowControlManagerMockRecorder { return _m.recorder } -// NewStream mocks base method -func (_m *MockFlowControlManager) NewStream(streamID protocol.StreamID, contributesToConnectionFlow bool) { - _m.ctrl.Call(_m, "NewStream", streamID, contributesToConnectionFlow) -} - -// NewStream indicates an expected call of NewStream -func (_mr *MockFlowControlManagerMockRecorder) NewStream(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "NewStream", reflect.TypeOf((*MockFlowControlManager)(nil).NewStream), arg0, arg1) -} - -// RemoveStream mocks base method -func (_m *MockFlowControlManager) RemoveStream(streamID protocol.StreamID) { - _m.ctrl.Call(_m, "RemoveStream", streamID) -} - -// RemoveStream indicates an expected call of RemoveStream -func (_mr *MockFlowControlManagerMockRecorder) RemoveStream(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "RemoveStream", reflect.TypeOf((*MockFlowControlManager)(nil).RemoveStream), arg0) -} - -// UpdateTransportParameters mocks base method -func (_m *MockFlowControlManager) UpdateTransportParameters(_param0 *handshake.TransportParameters) { - _m.ctrl.Call(_m, "UpdateTransportParameters", _param0) -} - -// UpdateTransportParameters indicates an expected call of UpdateTransportParameters -func (_mr *MockFlowControlManagerMockRecorder) UpdateTransportParameters(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateTransportParameters", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateTransportParameters), arg0) -} - -// ResetStream mocks base method -func (_m *MockFlowControlManager) ResetStream(streamID protocol.StreamID, byteOffset protocol.ByteCount) error { - ret := _m.ctrl.Call(_m, "ResetStream", streamID, byteOffset) - ret0, _ := ret[0].(error) - return ret0 -} - -// ResetStream indicates an expected call of ResetStream -func (_mr *MockFlowControlManagerMockRecorder) ResetStream(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "ResetStream", reflect.TypeOf((*MockFlowControlManager)(nil).ResetStream), arg0, arg1) -} - -// UpdateHighestReceived mocks base method -func (_m *MockFlowControlManager) UpdateHighestReceived(streamID protocol.StreamID, byteOffset protocol.ByteCount) error { - ret := _m.ctrl.Call(_m, "UpdateHighestReceived", streamID, byteOffset) - ret0, _ := ret[0].(error) - return ret0 -} - -// UpdateHighestReceived indicates an expected call of UpdateHighestReceived -func (_mr *MockFlowControlManagerMockRecorder) UpdateHighestReceived(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateHighestReceived", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateHighestReceived), arg0, arg1) -} - // AddBytesRead mocks base method -func (_m *MockFlowControlManager) AddBytesRead(streamID protocol.StreamID, n protocol.ByteCount) error { - ret := _m.ctrl.Call(_m, "AddBytesRead", streamID, n) +func (_m *MockFlowControlManager) AddBytesRead(_param0 protocol.StreamID, _param1 protocol.ByteCount) error { + ret := _m.ctrl.Call(_m, "AddBytesRead", _param0, _param1) ret0, _ := ret[0].(error) return ret0 } @@ -101,6 +47,31 @@ func (_mr *MockFlowControlManagerMockRecorder) AddBytesRead(arg0, arg1 interface return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "AddBytesRead", reflect.TypeOf((*MockFlowControlManager)(nil).AddBytesRead), arg0, arg1) } +// AddBytesSent mocks base method +func (_m *MockFlowControlManager) AddBytesSent(_param0 protocol.StreamID, _param1 protocol.ByteCount) error { + ret := _m.ctrl.Call(_m, "AddBytesSent", _param0, _param1) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddBytesSent indicates an expected call of AddBytesSent +func (_mr *MockFlowControlManagerMockRecorder) AddBytesSent(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "AddBytesSent", reflect.TypeOf((*MockFlowControlManager)(nil).AddBytesSent), arg0, arg1) +} + +// GetReceiveWindow mocks base method +func (_m *MockFlowControlManager) GetReceiveWindow(_param0 protocol.StreamID) (protocol.ByteCount, error) { + ret := _m.ctrl.Call(_m, "GetReceiveWindow", _param0) + ret0, _ := ret[0].(protocol.ByteCount) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetReceiveWindow indicates an expected call of GetReceiveWindow +func (_mr *MockFlowControlManagerMockRecorder) GetReceiveWindow(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetReceiveWindow", reflect.TypeOf((*MockFlowControlManager)(nil).GetReceiveWindow), arg0) +} + // GetWindowUpdates mocks base method func (_m *MockFlowControlManager) GetWindowUpdates() []flowcontrol.WindowUpdate { ret := _m.ctrl.Call(_m, "GetWindowUpdates") @@ -113,42 +84,14 @@ func (_mr *MockFlowControlManagerMockRecorder) GetWindowUpdates() *gomock.Call { return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetWindowUpdates", reflect.TypeOf((*MockFlowControlManager)(nil).GetWindowUpdates)) } -// GetReceiveWindow mocks base method -func (_m *MockFlowControlManager) GetReceiveWindow(streamID protocol.StreamID) (protocol.ByteCount, error) { - ret := _m.ctrl.Call(_m, "GetReceiveWindow", streamID) - ret0, _ := ret[0].(protocol.ByteCount) - ret1, _ := ret[1].(error) - return ret0, ret1 +// NewStream mocks base method +func (_m *MockFlowControlManager) NewStream(_param0 protocol.StreamID, _param1 bool) { + _m.ctrl.Call(_m, "NewStream", _param0, _param1) } -// GetReceiveWindow indicates an expected call of GetReceiveWindow -func (_mr *MockFlowControlManagerMockRecorder) GetReceiveWindow(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetReceiveWindow", reflect.TypeOf((*MockFlowControlManager)(nil).GetReceiveWindow), arg0) -} - -// AddBytesSent mocks base method -func (_m *MockFlowControlManager) AddBytesSent(streamID protocol.StreamID, n protocol.ByteCount) error { - ret := _m.ctrl.Call(_m, "AddBytesSent", streamID, n) - ret0, _ := ret[0].(error) - return ret0 -} - -// AddBytesSent indicates an expected call of AddBytesSent -func (_mr *MockFlowControlManagerMockRecorder) AddBytesSent(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "AddBytesSent", reflect.TypeOf((*MockFlowControlManager)(nil).AddBytesSent), arg0, arg1) -} - -// SendWindowSize mocks base method -func (_m *MockFlowControlManager) SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error) { - ret := _m.ctrl.Call(_m, "SendWindowSize", streamID) - ret0, _ := ret[0].(protocol.ByteCount) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SendWindowSize indicates an expected call of SendWindowSize -func (_mr *MockFlowControlManagerMockRecorder) SendWindowSize(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "SendWindowSize", reflect.TypeOf((*MockFlowControlManager)(nil).SendWindowSize), arg0) +// NewStream indicates an expected call of NewStream +func (_mr *MockFlowControlManagerMockRecorder) NewStream(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "NewStream", reflect.TypeOf((*MockFlowControlManager)(nil).NewStream), arg0, arg1) } // RemainingConnectionWindowSize mocks base method @@ -163,9 +106,68 @@ func (_mr *MockFlowControlManagerMockRecorder) RemainingConnectionWindowSize() * return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "RemainingConnectionWindowSize", reflect.TypeOf((*MockFlowControlManager)(nil).RemainingConnectionWindowSize)) } +// RemoveStream mocks base method +func (_m *MockFlowControlManager) RemoveStream(_param0 protocol.StreamID) { + _m.ctrl.Call(_m, "RemoveStream", _param0) +} + +// RemoveStream indicates an expected call of RemoveStream +func (_mr *MockFlowControlManagerMockRecorder) RemoveStream(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "RemoveStream", reflect.TypeOf((*MockFlowControlManager)(nil).RemoveStream), arg0) +} + +// ResetStream mocks base method +func (_m *MockFlowControlManager) ResetStream(_param0 protocol.StreamID, _param1 protocol.ByteCount) error { + ret := _m.ctrl.Call(_m, "ResetStream", _param0, _param1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ResetStream indicates an expected call of ResetStream +func (_mr *MockFlowControlManagerMockRecorder) ResetStream(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "ResetStream", reflect.TypeOf((*MockFlowControlManager)(nil).ResetStream), arg0, arg1) +} + +// SendWindowSize mocks base method +func (_m *MockFlowControlManager) SendWindowSize(_param0 protocol.StreamID) (protocol.ByteCount, error) { + ret := _m.ctrl.Call(_m, "SendWindowSize", _param0) + ret0, _ := ret[0].(protocol.ByteCount) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendWindowSize indicates an expected call of SendWindowSize +func (_mr *MockFlowControlManagerMockRecorder) SendWindowSize(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "SendWindowSize", reflect.TypeOf((*MockFlowControlManager)(nil).SendWindowSize), arg0) +} + +// UpdateConnectionWindow mocks base method +func (_m *MockFlowControlManager) UpdateConnectionWindow(_param0 protocol.ByteCount) bool { + ret := _m.ctrl.Call(_m, "UpdateConnectionWindow", _param0) + ret0, _ := ret[0].(bool) + return ret0 +} + +// UpdateConnectionWindow indicates an expected call of UpdateConnectionWindow +func (_mr *MockFlowControlManagerMockRecorder) UpdateConnectionWindow(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateConnectionWindow", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateConnectionWindow), arg0) +} + +// UpdateHighestReceived mocks base method +func (_m *MockFlowControlManager) UpdateHighestReceived(_param0 protocol.StreamID, _param1 protocol.ByteCount) error { + ret := _m.ctrl.Call(_m, "UpdateHighestReceived", _param0, _param1) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateHighestReceived indicates an expected call of UpdateHighestReceived +func (_mr *MockFlowControlManagerMockRecorder) UpdateHighestReceived(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateHighestReceived", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateHighestReceived), arg0, arg1) +} + // UpdateStreamWindow mocks base method -func (_m *MockFlowControlManager) UpdateStreamWindow(streamID protocol.StreamID, offset protocol.ByteCount) (bool, error) { - ret := _m.ctrl.Call(_m, "UpdateStreamWindow", streamID, offset) +func (_m *MockFlowControlManager) UpdateStreamWindow(_param0 protocol.StreamID, _param1 protocol.ByteCount) (bool, error) { + ret := _m.ctrl.Call(_m, "UpdateStreamWindow", _param0, _param1) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 @@ -176,14 +178,12 @@ func (_mr *MockFlowControlManagerMockRecorder) UpdateStreamWindow(arg0, arg1 int return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateStreamWindow", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateStreamWindow), arg0, arg1) } -// UpdateConnectionWindow mocks base method -func (_m *MockFlowControlManager) UpdateConnectionWindow(offset protocol.ByteCount) bool { - ret := _m.ctrl.Call(_m, "UpdateConnectionWindow", offset) - ret0, _ := ret[0].(bool) - return ret0 +// UpdateTransportParameters mocks base method +func (_m *MockFlowControlManager) UpdateTransportParameters(_param0 *handshake.TransportParameters) { + _m.ctrl.Call(_m, "UpdateTransportParameters", _param0) } -// UpdateConnectionWindow indicates an expected call of UpdateConnectionWindow -func (_mr *MockFlowControlManagerMockRecorder) UpdateConnectionWindow(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateConnectionWindow", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateConnectionWindow), arg0) +// UpdateTransportParameters indicates an expected call of UpdateTransportParameters +func (_mr *MockFlowControlManagerMockRecorder) UpdateTransportParameters(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "UpdateTransportParameters", reflect.TypeOf((*MockFlowControlManager)(nil).UpdateTransportParameters), arg0) } diff --git a/internal/mocks/gen.go b/internal/mocks/gen.go index 21c7c028e..cd59f3e53 100644 --- a/internal/mocks/gen.go +++ b/internal/mocks/gen.go @@ -1,7 +1,4 @@ package mocks -// mockgen source mode doesn't properly recognize structs defined in the same package -// so we have to use sed to correct for that - -//go:generate sh -c "mockgen -package mocks -source ../flowcontrol/interface.go | sed \"s/\\[\\]WindowUpdate/[]flowcontrol.WindowUpdate/g\" > flow_control_manager.go" +//go:generate sh -c "./mockgen_internal.sh mocks flow_control_manager.go github.com/lucas-clemente/quic-go/internal/flowcontrol FlowControlManager" //go:generate sh -c "goimports -w ." diff --git a/internal/mocks/mockgen_internal.sh b/internal/mocks/mockgen_internal.sh new file mode 100755 index 000000000..c37936200 --- /dev/null +++ b/internal/mocks/mockgen_internal.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Mockgen refuses to generate mocks for internal packages. +# This script copies the internal directory and renames it to internalpackage. +# That way, mockgen can generate the mock. +# Afterwards, it corrects the import paths (replaces internalpackage back to internal). + +TEMP_DIR=$(mktemp -d) +mkdir -p $TEMP_DIR/src/github.com/lucas-clemente/quic-go/internalpackage + +cp -r $GOPATH/src/github.com/lucas-clemente/quic-go/internal/* $TEMP_DIR/src/github.com/lucas-clemente/quic-go/internalpackage +find $TEMP_DIR -type f -name "*.go" -exec sed -i '' 's/internal/internalpackage/g' {} \; + +export GOPATH="$TEMP_DIR:$GOPATH" +PACKAGE_PATH=${3/internal/internalpackage} + + +mockgen -package $1 -self_package $1 -destination $2 $PACKAGE_PATH $4 +sed -i '' 's/internalpackage/internal/g' $2 + +rm -rf "$TEMP_DIR"