diff --git a/internal/handshake/mock_client_session_cache_test.go b/internal/handshake/mock_client_session_cache_test.go new file mode 100644 index 00000000..2e293cf1 --- /dev/null +++ b/internal/handshake/mock_client_session_cache_test.go @@ -0,0 +1,61 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: crypto/tls (interfaces: ClientSessionCache) + +// Package handshake is a generated GoMock package. +package handshake + +import ( + tls "crypto/tls" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockClientSessionCache is a mock of ClientSessionCache interface +type MockClientSessionCache struct { + ctrl *gomock.Controller + recorder *MockClientSessionCacheMockRecorder +} + +// MockClientSessionCacheMockRecorder is the mock recorder for MockClientSessionCache +type MockClientSessionCacheMockRecorder struct { + mock *MockClientSessionCache +} + +// NewMockClientSessionCache creates a new mock instance +func NewMockClientSessionCache(ctrl *gomock.Controller) *MockClientSessionCache { + mock := &MockClientSessionCache{ctrl: ctrl} + mock.recorder = &MockClientSessionCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockClientSessionCache) EXPECT() *MockClientSessionCacheMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockClientSessionCache) Get(arg0 string) (*tls.ClientSessionState, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0) + ret0, _ := ret[0].(*tls.ClientSessionState) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// Get indicates an expected call of Get +func (mr *MockClientSessionCacheMockRecorder) Get(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClientSessionCache)(nil).Get), arg0) +} + +// Put mocks base method +func (m *MockClientSessionCache) Put(arg0 string, arg1 *tls.ClientSessionState) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Put", arg0, arg1) +} + +// Put indicates an expected call of Put +func (mr *MockClientSessionCacheMockRecorder) Put(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockClientSessionCache)(nil).Put), arg0, arg1) +} diff --git a/internal/handshake/mockgen.go b/internal/handshake/mockgen.go index 1c3b24b0..49cd53f9 100644 --- a/internal/handshake/mockgen.go +++ b/internal/handshake/mockgen.go @@ -1,3 +1,4 @@ package handshake //go:generate sh -c "../mockgen_internal.sh handshake mock_handshake_runner_test.go github.com/lucas-clemente/quic-go/internal/handshake handshakeRunner" +//go:generate sh -c "mockgen -package handshake crypto/tls ClientSessionCache > mock_client_session_cache_test.go" diff --git a/internal/handshake/qtls_test.go b/internal/handshake/qtls_test.go index b999aebf..8a895a35 100644 --- a/internal/handshake/qtls_test.go +++ b/internal/handshake/qtls_test.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "errors" + gomock "github.com/golang/mock/gomock" "github.com/marten-seemann/qtls" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -24,21 +25,6 @@ func (h *mockExtensionHandler) ReceivedExtensions(msgType uint8, exts []qtls.Ext } func (*mockExtensionHandler) TransportParameters() <-chan []byte { panic("not implemented") } -type mockClientSessionCache struct { - get, put string - session *tls.ClientSessionState -} - -var _ tls.ClientSessionCache = &mockClientSessionCache{} - -func (c *mockClientSessionCache) Get(sessionKey string) (session *tls.ClientSessionState, ok bool) { - c.get = sessionKey - return c.session, false -} -func (c *mockClientSessionCache) Put(sessionKey string, cs *tls.ClientSessionState) { - c.put = sessionKey -} - var _ = Describe("qtls.Config generation", func() { It("sets MinVersion and MaxVersion", func() { tlsConf := &tls.Config{MinVersion: tls.VersionTLS11, MaxVersion: tls.VersionTLS12} @@ -127,31 +113,17 @@ var _ = Describe("qtls.Config generation", func() { }) It("sets it, and puts and gets session states", func() { - state := &qtls.ClientSessionState{} - csc := &mockClientSessionCache{session: &tls.ClientSessionState{}} + csc := NewMockClientSessionCache(mockCtrl) tlsConf := &tls.Config{ClientSessionCache: csc} qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}) Expect(qtlsConf.ClientSessionCache).ToNot(BeNil()) - Expect(csc.put).To(BeEmpty()) - qtlsConf.ClientSessionCache.Put("foobar", state) - Expect(csc.put).To(Equal("foobar")) - Expect(csc.get).To(BeEmpty()) - sess, _ := qtlsConf.ClientSessionCache.Get("raboof") - Expect(csc.get).To(Equal("raboof")) - Expect(sess).To(Equal(state)) - }) - - It("sets it, and gets nil session states for unknown keys", func() { - csc := &mockClientSessionCache{} - tlsConf := &tls.Config{ - ClientSessionCache: csc, - } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}) - Expect(qtlsConf.ClientSessionCache).ToNot(BeNil()) - Expect(csc.get).To(BeEmpty()) - sess, _ := qtlsConf.ClientSessionCache.Get("raboof") - Expect(csc.get).To(Equal("raboof")) - Expect(sess).To(BeNil()) + // put something + csc.EXPECT().Put("foobar", gomock.Any()) + qtlsConf.ClientSessionCache.Put("foobar", &qtls.ClientSessionState{}) + // get something + csc.EXPECT().Get("raboof").Return(nil, true) + _, ok := qtlsConf.ClientSessionCache.Get("raboof") + Expect(ok).To(BeTrue()) }) }) })