From e0824e31638522615154cbe9cefb613db3285e31 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 9 Sep 2020 15:11:08 +0700 Subject: [PATCH] move the logging mock implementations to a separate package --- client_test.go | 14 +++++++------- config_test.go | 4 ++-- internal/mocks/{ => logging}/connection_tracer.go | 4 ++-- internal/mocks/{ => logging}/tracer.go | 4 ++-- internal/mocks/mockgen.go | 4 ++-- multiplexer_test.go | 8 ++++---- packet_handler_map_test.go | 6 +++--- server_test.go | 7 +++---- session_test.go | 9 +++++---- 9 files changed, 30 insertions(+), 30 deletions(-) rename internal/mocks/{ => logging}/connection_tracer.go (99%) rename internal/mocks/{ => logging}/tracer.go (97%) diff --git a/client_test.go b/client_test.go index b22aa29f..2d1b090a 100644 --- a/client_test.go +++ b/client_test.go @@ -9,15 +9,15 @@ import ( "os" "time" - "github.com/lucas-clemente/quic-go/logging" - - "github.com/golang/mock/gomock" - "github.com/lucas-clemente/quic-go/internal/mocks" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" + "github.com/lucas-clemente/quic-go/logging" "github.com/lucas-clemente/quic-go/quictrace" + "github.com/golang/mock/gomock" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -31,7 +31,7 @@ var _ = Describe("Client", func() { mockMultiplexer *MockMultiplexer origMultiplexer multiplexer tlsConf *tls.Config - tracer *mocks.MockConnectionTracer + tracer *mocklogging.MockConnectionTracer config *Config originalClientSessConstructor func( @@ -66,8 +66,8 @@ var _ = Describe("Client", func() { tlsConf = &tls.Config{NextProtos: []string{"proto1"}} connID = protocol.ConnectionID{0, 0, 0, 0, 0, 0, 0x13, 0x37} originalClientSessConstructor = newClientSession - tracer = mocks.NewMockConnectionTracer(mockCtrl) - tr := mocks.NewMockTracer(mockCtrl) + tracer = mocklogging.NewMockConnectionTracer(mockCtrl) + tr := mocklogging.NewMockTracer(mockCtrl) tr.EXPECT().TracerForConnection(protocol.PerspectiveClient, gomock.Any()).Return(tracer).MaxTimes(1) config = &Config{Tracer: tr} Eventually(areSessionsRunning).Should(BeFalse()) diff --git a/config_test.go b/config_test.go index ad9b23c7..d7199646 100644 --- a/config_test.go +++ b/config_test.go @@ -6,7 +6,7 @@ import ( "reflect" "time" - "github.com/lucas-clemente/quic-go/internal/mocks" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/quictrace" @@ -73,7 +73,7 @@ var _ = Describe("Config", func() { case "QuicTracer": f.Set(reflect.ValueOf(quictrace.NewTracer())) case "Tracer": - f.Set(reflect.ValueOf(mocks.NewMockTracer(mockCtrl))) + f.Set(reflect.ValueOf(mocklogging.NewMockTracer(mockCtrl))) default: Fail(fmt.Sprintf("all fields must be accounted for, but saw unknown field %q", fn)) } diff --git a/internal/mocks/connection_tracer.go b/internal/mocks/logging/connection_tracer.go similarity index 99% rename from internal/mocks/connection_tracer.go rename to internal/mocks/logging/connection_tracer.go index aac749ba..a91694e9 100644 --- a/internal/mocks/connection_tracer.go +++ b/internal/mocks/logging/connection_tracer.go @@ -1,8 +1,8 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/lucas-clemente/quic-go/logging (interfaces: ConnectionTracer) -// Package mocks is a generated GoMock package. -package mocks +// Package mocklogging is a generated GoMock package. +package mocklogging import ( net "net" diff --git a/internal/mocks/tracer.go b/internal/mocks/logging/tracer.go similarity index 97% rename from internal/mocks/tracer.go rename to internal/mocks/logging/tracer.go index 4ed0d14d..2a643e35 100644 --- a/internal/mocks/tracer.go +++ b/internal/mocks/logging/tracer.go @@ -1,8 +1,8 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/lucas-clemente/quic-go/logging (interfaces: Tracer) -// Package mocks is a generated GoMock package. -package mocks +// Package mocklogging is a generated GoMock package. +package mocklogging import ( net "net" diff --git a/internal/mocks/mockgen.go b/internal/mocks/mockgen.go index c2128c2d..fb38a3cc 100644 --- a/internal/mocks/mockgen.go +++ b/internal/mocks/mockgen.go @@ -3,8 +3,8 @@ package mocks //go:generate sh -c "mockgen -package mockquic -destination quic/stream.go github.com/lucas-clemente/quic-go Stream && goimports -w quic/stream.go" //go:generate sh -c "mockgen -package mockquic -destination quic/early_session_tmp.go github.com/lucas-clemente/quic-go EarlySession && sed 's/qtls.ConnectionState/quic.ConnectionState/g' quic/early_session_tmp.go > quic/early_session.go && rm quic/early_session_tmp.go && goimports -w quic/early_session.go" //go:generate sh -c "mockgen -package mockquic -destination quic/early_listener.go github.com/lucas-clemente/quic-go EarlyListener && goimports -w quic/early_listener.go" -//go:generate sh -c "mockgen -package mocks -destination tracer.go github.com/lucas-clemente/quic-go/logging Tracer && goimports -w tracer.go" -//go:generate sh -c "mockgen -package mocks -destination connection_tracer.go github.com/lucas-clemente/quic-go/logging ConnectionTracer && goimports -w connection_tracer.go" +//go:generate sh -c "mockgen -package mocklogging -destination logging/tracer.go github.com/lucas-clemente/quic-go/logging Tracer && goimports -w logging/tracer.go" +//go:generate sh -c "mockgen -package mocklogging -destination logging/connection_tracer.go github.com/lucas-clemente/quic-go/logging ConnectionTracer && goimports -w logging/connection_tracer.go" //go:generate sh -c "mockgen -package mocks -destination short_header_sealer.go github.com/lucas-clemente/quic-go/internal/handshake ShortHeaderSealer && goimports -w short_header_sealer.go" //go:generate sh -c "mockgen -package mocks -destination short_header_opener.go github.com/lucas-clemente/quic-go/internal/handshake ShortHeaderOpener && goimports -w short_header_opener.go" //go:generate sh -c "mockgen -package mocks -destination long_header_opener.go github.com/lucas-clemente/quic-go/internal/handshake LongHeaderOpener && goimports -w long_header_opener.go" diff --git a/multiplexer_test.go b/multiplexer_test.go index 4141c46c..5faa701e 100644 --- a/multiplexer_test.go +++ b/multiplexer_test.go @@ -3,7 +3,7 @@ package quic import ( "net" - "github.com/lucas-clemente/quic-go/internal/mocks" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -25,7 +25,7 @@ var _ = Describe("Client Multiplexer", func() { pconn := newMockPacketConn() pconn.addr = &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 4321} conn := testConn{PacketConn: pconn} - tracer := mocks.NewMockTracer(mockCtrl) + tracer := mocklogging.NewMockTracer(mockCtrl) _, err := getMultiplexer().AddConn(conn, 8, []byte("foobar"), tracer) Expect(err).ToNot(HaveOccurred()) conn.counter++ @@ -52,9 +52,9 @@ var _ = Describe("Client Multiplexer", func() { It("errors when adding an existing conn with different tracers", func() { conn := newMockPacketConn() - _, err := getMultiplexer().AddConn(conn, 7, nil, mocks.NewMockTracer(mockCtrl)) + _, err := getMultiplexer().AddConn(conn, 7, nil, mocklogging.NewMockTracer(mockCtrl)) Expect(err).ToNot(HaveOccurred()) - _, err = getMultiplexer().AddConn(conn, 7, nil, mocks.NewMockTracer(mockCtrl)) + _, err = getMultiplexer().AddConn(conn, 7, nil, mocklogging.NewMockTracer(mockCtrl)) Expect(err).To(MatchError("cannot use different tracers on the same packet conn")) }) }) diff --git a/packet_handler_map_test.go b/packet_handler_map_test.go index b2e99355..5e7e1a2b 100644 --- a/packet_handler_map_test.go +++ b/packet_handler_map_test.go @@ -7,7 +7,7 @@ import ( "net" "time" - "github.com/lucas-clemente/quic-go/internal/mocks" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" @@ -23,7 +23,7 @@ var _ = Describe("Packet Handler Map", func() { var ( handler *packetHandlerMap conn *mockPacketConn - tracer *mocks.MockTracer + tracer *mocklogging.MockTracer connIDLen int statelessResetKey []byte @@ -51,7 +51,7 @@ var _ = Describe("Packet Handler Map", func() { BeforeEach(func() { statelessResetKey = nil connIDLen = 0 - tracer = mocks.NewMockTracer(mockCtrl) + tracer = mocklogging.NewMockTracer(mockCtrl) }) JustBeforeEach(func() { diff --git a/server_test.go b/server_test.go index b866c393..a2a9278a 100644 --- a/server_test.go +++ b/server_test.go @@ -14,9 +14,8 @@ import ( "sync/atomic" "time" - "github.com/lucas-clemente/quic-go/internal/mocks" - "github.com/lucas-clemente/quic-go/internal/handshake" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/testdata" @@ -186,11 +185,11 @@ var _ = Describe("Server", func() { var ( serv *baseServer phm *MockPacketHandlerManager - tracer *mocks.MockTracer + tracer *mocklogging.MockTracer ) BeforeEach(func() { - tracer = mocks.NewMockTracer(mockCtrl) + tracer = mocklogging.NewMockTracer(mockCtrl) ln, err := Listen(conn, tlsConf, &Config{Tracer: tracer}) Expect(err).ToNot(HaveOccurred()) serv = ln.(*baseServer) diff --git a/session_test.go b/session_test.go index e7901cce..07cb3e91 100644 --- a/session_test.go +++ b/session_test.go @@ -17,6 +17,7 @@ import ( "github.com/lucas-clemente/quic-go/internal/handshake" "github.com/lucas-clemente/quic-go/internal/mocks" mockackhandler "github.com/lucas-clemente/quic-go/internal/mocks/ackhandler" + mocklogging "github.com/lucas-clemente/quic-go/internal/mocks/logging" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/testutils" @@ -50,7 +51,7 @@ var _ = Describe("Session", func() { streamManager *MockStreamManager packer *MockPacker cryptoSetup *mocks.MockCryptoSetup - tracer *mocks.MockConnectionTracer + tracer *mocklogging.MockConnectionTracer ) remoteAddr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337} localAddr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 7331} @@ -88,7 +89,7 @@ var _ = Describe("Session", func() { mconn.EXPECT().LocalAddr().Return(localAddr).AnyTimes() tokenGenerator, err := handshake.NewTokenGenerator(rand.Reader) Expect(err).ToNot(HaveOccurred()) - tracer = mocks.NewMockConnectionTracer(mockCtrl) + tracer = mocklogging.NewMockConnectionTracer(mockCtrl) tracer.EXPECT().SentTransportParameters(gomock.Any()) tracer.EXPECT().UpdatedKeyFromTLS(gomock.Any(), gomock.Any()).AnyTimes() tracer.EXPECT().UpdatedCongestionState(gomock.Any()) @@ -2109,7 +2110,7 @@ var _ = Describe("Client Session", func() { packer *MockPacker mconn *MockSendConn cryptoSetup *mocks.MockCryptoSetup - tracer *mocks.MockConnectionTracer + tracer *mocklogging.MockConnectionTracer tlsConf *tls.Config quicConf *Config ) @@ -2148,7 +2149,7 @@ var _ = Describe("Client Session", func() { tlsConf = &tls.Config{} } sessionRunner = NewMockSessionRunner(mockCtrl) - tracer = mocks.NewMockConnectionTracer(mockCtrl) + tracer = mocklogging.NewMockConnectionTracer(mockCtrl) tracer.EXPECT().SentTransportParameters(gomock.Any()) tracer.EXPECT().UpdatedKeyFromTLS(gomock.Any(), gomock.Any()).AnyTimes() tracer.EXPECT().UpdatedCongestionState(gomock.Any())