update gomock, simplify script for generation mocks of private types

This commit is contained in:
Marten Seemann 2020-01-26 12:53:41 +07:00
parent fe026a3ac1
commit c809166cab
7 changed files with 36 additions and 40 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
debug
debug.test
main
mockgen_tmp.go
*.qtr
fuzzing/*/*.zip

4
go.mod
View file

@ -5,7 +5,7 @@ go 1.13
require (
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75
github.com/cheekybits/genny v1.0.0
github.com/golang/mock v1.2.0
github.com/golang/mock v1.4.0
github.com/golang/protobuf v1.3.0
github.com/marten-seemann/chacha20 v0.2.0
github.com/marten-seemann/qpack v0.1.0
@ -14,5 +14,5 @@ require (
github.com/onsi/gomega v1.4.3
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
golang.org/x/sync v0.0.0-20190423024810-112230192c58
)

12
go.sum
View file

@ -4,8 +4,8 @@ github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitf
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.4.0 h1:Rd1kQnQu0Hq3qvJppYSG0HtP+f5LPPUiDswTLiEegLg=
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
@ -28,18 +28,24 @@ golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190228165749-92fc7df08ae7 h1:Qe/u+eY379X4He4GBMFZYu3pmh1ML5yT1aL1ndNM1zQ=
golang.org/x/net v0.0.0-20190228165749-92fc7df08ae7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@ -49,3 +55,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

View file

@ -10,7 +10,7 @@ import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
quic_go "github.com/lucas-clemente/quic-go"
quic "github.com/lucas-clemente/quic-go"
)
// MockListener is a mock of Listener interface
@ -37,10 +37,10 @@ func (m *MockListener) EXPECT() *MockListenerMockRecorder {
}
// Accept mocks base method
func (m *MockListener) Accept(arg0 context.Context) (quic_go.Session, error) {
func (m *MockListener) Accept(arg0 context.Context) (quic.Session, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Accept", arg0)
ret0, _ := ret[0].(quic_go.Session)
ret0, _ := ret[0].(quic.Session)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View file

@ -11,7 +11,7 @@ import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
quic_go "github.com/lucas-clemente/quic-go"
quic "github.com/lucas-clemente/quic-go"
protocol "github.com/lucas-clemente/quic-go/internal/protocol"
)
@ -39,10 +39,10 @@ func (m *MockSession) EXPECT() *MockSessionMockRecorder {
}
// AcceptStream mocks base method
func (m *MockSession) AcceptStream(arg0 context.Context) (quic_go.Stream, error) {
func (m *MockSession) AcceptStream(arg0 context.Context) (quic.Stream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AcceptStream", arg0)
ret0, _ := ret[0].(quic_go.Stream)
ret0, _ := ret[0].(quic.Stream)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -54,10 +54,10 @@ func (mr *MockSessionMockRecorder) AcceptStream(arg0 interface{}) *gomock.Call {
}
// AcceptUniStream mocks base method
func (m *MockSession) AcceptUniStream(arg0 context.Context) (quic_go.ReceiveStream, error) {
func (m *MockSession) AcceptUniStream(arg0 context.Context) (quic.ReceiveStream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AcceptUniStream", arg0)
ret0, _ := ret[0].(quic_go.ReceiveStream)
ret0, _ := ret[0].(quic.ReceiveStream)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -139,10 +139,10 @@ func (mr *MockSessionMockRecorder) LocalAddr() *gomock.Call {
}
// OpenStream mocks base method
func (m *MockSession) OpenStream() (quic_go.Stream, error) {
func (m *MockSession) OpenStream() (quic.Stream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OpenStream")
ret0, _ := ret[0].(quic_go.Stream)
ret0, _ := ret[0].(quic.Stream)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -154,10 +154,10 @@ func (mr *MockSessionMockRecorder) OpenStream() *gomock.Call {
}
// OpenStreamSync mocks base method
func (m *MockSession) OpenStreamSync(arg0 context.Context) (quic_go.Stream, error) {
func (m *MockSession) OpenStreamSync(arg0 context.Context) (quic.Stream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OpenStreamSync", arg0)
ret0, _ := ret[0].(quic_go.Stream)
ret0, _ := ret[0].(quic.Stream)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -169,10 +169,10 @@ func (mr *MockSessionMockRecorder) OpenStreamSync(arg0 interface{}) *gomock.Call
}
// OpenUniStream mocks base method
func (m *MockSession) OpenUniStream() (quic_go.SendStream, error) {
func (m *MockSession) OpenUniStream() (quic.SendStream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OpenUniStream")
ret0, _ := ret[0].(quic_go.SendStream)
ret0, _ := ret[0].(quic.SendStream)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -184,10 +184,10 @@ func (mr *MockSessionMockRecorder) OpenUniStream() *gomock.Call {
}
// OpenUniStreamSync mocks base method
func (m *MockSession) OpenUniStreamSync(arg0 context.Context) (quic_go.SendStream, error) {
func (m *MockSession) OpenUniStreamSync(arg0 context.Context) (quic.SendStream, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "OpenUniStreamSync", arg0)
ret0, _ := ret[0].(quic_go.SendStream)
ret0, _ := ret[0].(quic.SendStream)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View file

@ -20,4 +20,4 @@ package quic
//go:generate sh -c "./mockgen_private.sh quic mock_unknown_packet_handler_test.go github.com/lucas-clemente/quic-go unknownPacketHandler"
//go:generate sh -c "./mockgen_private.sh quic mock_packet_handler_manager_test.go github.com/lucas-clemente/quic-go packetHandlerManager"
//go:generate sh -c "./mockgen_private.sh quic mock_multiplexer_test.go github.com/lucas-clemente/quic-go multiplexer"
//go:generate sh -c "mockgen -package quic -destination mock_token_store_test.go github.com/lucas-clemente/quic-go TokenStore && sed -i '' 's/quic_go.//g' mock_token_store_test.go && goimports -w mock_token_store_test.go"
//go:generate sh -c "mockgen -package quic -self_package github.com/lucas-clemente/quic-go -destination mock_token_store_test.go github.com/lucas-clemente/quic-go TokenStore && goimports -w mock_token_store_test.go"

View file

@ -1,28 +1,15 @@
#!/bin/bash
# Mockgen refuses to generate mocks private types.
# This script copies the quic package to a temporary directory, and adds an public alias for the private type.
# It then creates a mock for this public (alias) type.
TEMP_DIR=$(mktemp -d)
mkdir -p $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
PACKAGE=$3
TMPFILE="mockgen_tmp.go"
# uppercase the name of the interface
INTERFACE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${4:0:1})${4:1}"
# copy all .go files to a temporary directory
rsync -r --exclude 'vendor' --include='*.go' --include '*/' --exclude '*' $GOPATH/src/github.com/lucas-clemente/quic-go/ $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
# create a public alias for the interface, so that mockgen can process it
echo -e "package $1\n" > $TEMP_DIR/src/github.com/lucas-clemente/quic-go/mockgen_interface.go
echo "type $INTERFACE_NAME = $4" >> $TEMP_DIR/src/github.com/lucas-clemente/quic-go/mockgen_interface.go
echo -e "package $1\n" > $TMPFILE
echo "type $INTERFACE_NAME = $4" >> $TMPFILE
export GOPATH="$TEMP_DIR:$GOPATH"
mockgen -package $1 -self_package $1 -destination $2 $3 $INTERFACE_NAME
# mockgen imports quic-go as 'import quic_go github.com/lucas_clemente/quic-go'
sed -i '' 's/quic_go.//g' $2
mockgen -package $1 -self_package $PACKAGE -destination $2 $PACKAGE $INTERFACE_NAME
goimports -w $2
rm -r "$TEMP_DIR"
rm $TMPFILE