-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
55 lines (39 loc) · 1.15 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package nats
import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"gofr.dev/pkg/gofr/logging"
"gofr.dev/pkg/gofr/testutil"
)
func TestNewNATSMessage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockMsg := NewMockMsg(ctrl)
logger := logging.NewMockLogger(logging.ERROR)
n := newNATSMessage(mockMsg, logger)
assert.NotNil(t, n)
assert.Equal(t, mockMsg, n.msg)
assert.Equal(t, logger, n.logger)
}
func TestNATSMessage_Commit(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockMsg := NewMockMsg(ctrl)
logger := logging.NewMockLogger(logging.ERROR)
n := newNATSMessage(mockMsg, logger)
mockMsg.EXPECT().Ack().Return(nil)
n.Commit()
}
func TestNATSMessage_CommitError(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockMsg := NewMockMsg(ctrl)
out := testutil.StderrOutputForFunc(func() {
logger := logging.NewMockLogger(logging.ERROR)
n := newNATSMessage(mockMsg, logger)
mockMsg.EXPECT().Ack().Return(testutil.CustomError{ErrorMessage: "ack error"})
n.Commit()
})
assert.Contains(t, out, "unable to acknowledge message on Client JetStream")
}