Skip to content

Commit

Permalink
fix. tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imperiuse committed Feb 28, 2021
1 parent 54f8b51 commit d94e1a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
13 changes: 7 additions & 6 deletions nats/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (suite *NatsClientTestSuit) Test_BadRequestReply() {
request := request
err := suite.natsClient.Request(ctx, subj, &request, reply)
assert.NotNil(suite.T(), err, "Must be err")
assert.Equal(suite.T(), m.ErrBadDataMock, err, "must be err errBadDataMock")
assert.Equal(suite.T(), m.ErrBadDataMock, errors.Cause(err), "must be err errBadDataMock")
}
done <- struct{}{}
}(sendChan, done)
Expand All @@ -331,33 +331,34 @@ func (suite *NatsClientTestSuit) Test_BadSubscribe() {
})
assert.Nil(suite.T(), s, "must be nil")
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")
}

func (suite *NatsClientTestSuit) Test_BadRequest1() {
const timeoutNatsRequest = time.Second
ctx, cancelFunc := context.WithTimeout(context.Background(), timeoutNatsRequest)
defer cancelFunc()

errBad := errors.New("bad")
const errStrBad = "bad"
errBad := errors.New(errStrBad)
suite.mockNats.On("RequestWithContext", mock.Anything, mock.AnythingOfType("string"), mock.Anything).Return(&Msg{}, errBad)
err := suite.badNatsClient.Request(ctx, "testSubj", &m.DataMock{Data: []byte("mock data")}, &m.DataMock{})
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")

// it's hack, because you can't change hook with On() function =(
suite.mockNats = &mocks.PureNatsConnI{}
suite.badNatsClient.conn = suite.mockNats
suite.mockNats.On("RequestWithContext", mock.Anything, mock.AnythingOfType("string"), mock.Anything).Return(nil, nil)
err = suite.badNatsClient.Request(ctx, "testSubj", &m.DataMock{Data: []byte("mock data")}, &m.DataMock{})
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), ErrEmptyMsg, err, "must be equals")
assert.Equal(suite.T(), ErrEmptyMsg, errors.Cause(err), "must be equals")

// it's hack, because you can't change hook with On() function =(
suite.mockNats = &mocks.PureNatsConnI{}
suite.badNatsClient.conn = suite.mockNats
suite.mockNats.On("RequestWithContext", mock.Anything, mock.AnythingOfType("string"), mock.Anything).Return(nil, errBad)
err = suite.badNatsClient.Request(ctx, "testSubj", &m.DataMock{Data: []byte("mock data")}, &m.DataMock{})
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")
}
22 changes: 11 additions & 11 deletions streaming/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (suite *NatsStreamingClientTestSuit) SetupSuite() {

badNatsClient := nc.NewDefaultClient()
c1, err := New(DefaultClusterID, fmt.Sprint(uuid.Must(uuid.NewV4())), badNatsClient)
assert.Equal(suite.T(), ErrNilNatsConn, err)
assert.Equal(suite.T(), ErrNilNatsConn, errors.Cause(err))
assert.Nil(suite.T(), c1, "client must be nil!")

natsClient, err := nc.New(testDSN)
Expand Down Expand Up @@ -116,7 +116,7 @@ func (suite *NatsStreamingClientTestSuit) Test_PublishSync() {

err = suite.streamingClient.PublishSync("Test_PublishSync", &mock.BadDataMock{})
assert.NotNil(suite.T(), err, "PublishSync must return err")
assert.Equal(suite.T(), mock.ErrBadDataMock, err)
assert.Equal(suite.T(), mock.ErrBadDataMock, errors.Cause(err))
}

func (suite *NatsStreamingClientTestSuit) Test_PublishAsync() {
Expand All @@ -126,7 +126,7 @@ func (suite *NatsStreamingClientTestSuit) Test_PublishAsync() {

guid, err = suite.streamingClient.PublishAsync("Test_PublishAsync", &mock.BadDataMock{}, nil)
assert.NotNil(suite.T(), err, "PublishAsync must return err")
assert.Equal(suite.T(), mock.ErrBadDataMock, err)
assert.Equal(suite.T(), mock.ErrBadDataMock, errors.Cause(err))
assert.Equal(suite.T(), EmptyGUID, guid, "GUID must be empty")
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (suite *NatsStreamingClientTestSuit) Test_BadPublish() {

err := suite.badStreamingClient.PublishSync("testSubj", &mock.DataMock{Data: []byte("test_data")})
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")

guid, err := suite.badStreamingClient.PublishAsync("testSubj", &mock.DataMock{Data: []byte("test_data")}, suite.badStreamingClient.DefaultAckHandler())
assert.NotNil(suite.T(), err, "must be err")
Expand All @@ -187,7 +187,7 @@ func (suite *NatsStreamingClientTestSuit) Test_BadSubscribe() {
s, err := suite.badStreamingClient.Subscribe("testSubj", &mock.DataMock{}, EmptyHandler)
assert.Nil(suite.T(), s, "must be nil")
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")
}

func (suite *NatsStreamingClientTestSuit) Test_PingPongDummyTest() {
Expand Down Expand Up @@ -335,19 +335,19 @@ func (suite *NatsStreamingClientTestSuit) Test_CheckNilNatsClient() {
c := client{}

_, err := c.ReplyHandler("", &mock.DataMock{}, nil)
assert.Equal(suite.T(), ErrNilNatsClient, err)
assert.Equal(suite.T(), ErrNilNatsClient, errors.Cause(err))

err = c.Request(context.Background(), "", &mock.DataMock{}, &mock.DataMock{})
assert.Equal(suite.T(), ErrNilNatsClient, err)
assert.Equal(suite.T(), ErrNilNatsClient, errors.Cause(err))

_, err = c.PongHandler("")
assert.Equal(suite.T(), ErrNilNatsClient, err)
assert.Equal(suite.T(), ErrNilNatsClient, errors.Cause(err))

_, err = c.Ping(context.Background(), "")
assert.Equal(suite.T(), ErrNilNatsClient, err)
assert.Equal(suite.T(), ErrNilNatsClient, errors.Cause(err))

_, err = c.PongQueueHandler("", "")
assert.Equal(suite.T(), ErrNilNatsClient, err)
assert.Equal(suite.T(), ErrNilNatsClient, errors.Cause(err))
}

func (suite *NatsStreamingClientTestSuit) Test_QueueSubscribe() {
Expand Down Expand Up @@ -456,5 +456,5 @@ func (suite *NatsStreamingClientTestSuit) Test_BadQueueSubscriber() {
s, err := suite.badStreamingClient.QueueSubscribe("testSubj", "testQ", &mock.DataMock{}, EmptyHandler)
assert.Nil(suite.T(), s, "must be nil")
assert.NotNil(suite.T(), err, "must be err")
assert.Equal(suite.T(), errBad, err, "must be equals")
assert.Equal(suite.T(), errBad, errors.Cause(err), "must be equals")
}

0 comments on commit d94e1a6

Please sign in to comment.