diff --git a/conn_test.go b/conn_test.go index e01e6fa..96c6a95 100644 --- a/conn_test.go +++ b/conn_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-stomp/stomp/v3/frame" "github.com/go-stomp/stomp/v3/testutil" + + "github.com/golang/mock/gomock" . "gopkg.in/check.v1" ) @@ -28,6 +30,35 @@ func (rw *fakeReaderWriter) Close() error { return rw.conn.Close() } +func (s *StompSuite) Test_conn_option_set_logger(c *C) { + fc1, fc2 := testutil.NewFakeConn(c) + go func() { + + defer func() { + fc2.Close() + fc1.Close() + }() + + reader := frame.NewReader(fc2) + writer := frame.NewWriter(fc2) + f1, err := reader.Read() + c.Assert(err, IsNil) + c.Assert(f1.Command, Equals, "CONNECT") + f2 := frame.New("CONNECTED") + err = writer.Write(f2) + c.Assert(err, IsNil) + }() + + ctrl := gomock.NewController(s.t) + mockLogger := testutil.NewMockLogger(ctrl) + + conn, err := Connect(fc1, ConnOpt.Logger(mockLogger)) + c.Assert(err, IsNil) + c.Check(conn, NotNil) + + c.Assert(conn.log, Equals, mockLogger) +} + func (s *StompSuite) Test_unsuccessful_connect(c *C) { fc1, fc2 := testutil.NewFakeConn(c) stop := make(chan struct{}) diff --git a/go.mod b/go.mod index f8cabe8..365a3bd 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/go-stomp/stomp/v3 go 1.15 -require gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c +require ( + github.com/golang/mock v1.6.0 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c +) diff --git a/go.sum b/go.sum index 0c3aa11..1f0429d 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,32 @@ +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/stomp_test.go b/stomp_test.go index 79518a2..f8feca0 100644 --- a/stomp_test.go +++ b/stomp_test.go @@ -1,16 +1,18 @@ package stomp import ( - "gopkg.in/check.v1" "testing" + + "gopkg.in/check.v1" ) // Runs all gocheck tests in this package. // See other *_test.go files for gocheck tests. func TestStomp(t *testing.T) { + check.Suite(&StompSuite{t}) check.TestingT(t) } -type StompSuite struct{} - -var _ = check.Suite(&StompSuite{}) +type StompSuite struct { + t *testing.T +} diff --git a/testutil/mock_logger.go b/testutil/mock_logger.go new file mode 100644 index 0000000..4bd99e0 --- /dev/null +++ b/testutil/mock_logger.go @@ -0,0 +1,150 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./logger.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" +) + +// MockLogger is a mock of Logger interface. +type MockLogger struct { + ctrl *gomock.Controller + recorder *MockLoggerMockRecorder +} + +// MockLoggerMockRecorder is the mock recorder for MockLogger. +type MockLoggerMockRecorder struct { + mock *MockLogger +} + +// NewMockLogger creates a new mock instance. +func NewMockLogger(ctrl *gomock.Controller) *MockLogger { + mock := &MockLogger{ctrl: ctrl} + mock.recorder = &MockLoggerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLogger) EXPECT() *MockLoggerMockRecorder { + return m.recorder +} + +// Debug mocks base method. +func (m *MockLogger) Debug(message string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Debug", message) +} + +// Debug indicates an expected call of Debug. +func (mr *MockLoggerMockRecorder) Debug(message interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockLogger)(nil).Debug), message) +} + +// Debugf mocks base method. +func (m *MockLogger) Debugf(format string, value ...interface{}) { + m.ctrl.T.Helper() + varargs := []interface{}{format} + for _, a := range value { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Debugf", varargs...) +} + +// Debugf indicates an expected call of Debugf. +func (mr *MockLoggerMockRecorder) Debugf(format interface{}, value ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{format}, value...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debugf", reflect.TypeOf((*MockLogger)(nil).Debugf), varargs...) +} + +// Error mocks base method. +func (m *MockLogger) Error(message string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Error", message) +} + +// Error indicates an expected call of Error. +func (mr *MockLoggerMockRecorder) Error(message interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockLogger)(nil).Error), message) +} + +// Errorf mocks base method. +func (m *MockLogger) Errorf(format string, value ...interface{}) { + m.ctrl.T.Helper() + varargs := []interface{}{format} + for _, a := range value { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Errorf", varargs...) +} + +// Errorf indicates an expected call of Errorf. +func (mr *MockLoggerMockRecorder) Errorf(format interface{}, value ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{format}, value...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Errorf", reflect.TypeOf((*MockLogger)(nil).Errorf), varargs...) +} + +// Info mocks base method. +func (m *MockLogger) Info(message string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Info", message) +} + +// Info indicates an expected call of Info. +func (mr *MockLoggerMockRecorder) Info(message interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockLogger)(nil).Info), message) +} + +// Infof mocks base method. +func (m *MockLogger) Infof(format string, value ...interface{}) { + m.ctrl.T.Helper() + varargs := []interface{}{format} + for _, a := range value { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Infof", varargs...) +} + +// Infof indicates an expected call of Infof. +func (mr *MockLoggerMockRecorder) Infof(format interface{}, value ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{format}, value...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Infof", reflect.TypeOf((*MockLogger)(nil).Infof), varargs...) +} + +// Warning mocks base method. +func (m *MockLogger) Warning(message string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Warning", message) +} + +// Warning indicates an expected call of Warning. +func (mr *MockLoggerMockRecorder) Warning(message interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warning", reflect.TypeOf((*MockLogger)(nil).Warning), message) +} + +// Warningf mocks base method. +func (m *MockLogger) Warningf(format string, value ...interface{}) { + m.ctrl.T.Helper() + varargs := []interface{}{format} + for _, a := range value { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Warningf", varargs...) +} + +// Warningf indicates an expected call of Warningf. +func (mr *MockLoggerMockRecorder) Warningf(format interface{}, value ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{format}, value...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warningf", reflect.TypeOf((*MockLogger)(nil).Warningf), varargs...) +}