Untitled

mail@pastecode.io avatar
unknown
golang
a year ago
938 B
27
Indexable
Never
package rabbitmq

import (
	"events/errors"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestMessage_Acknowledge(t *testing.T) {
	testCases := []struct {
		name   string
		action func(t *testing.T, msg *Message) error
		assert func(t *testing.T, err error)
	}{
		{
			name: "success",
			action: func(t *testing.T, msg *Message) error {
				return msg.Acknowledge(true)
			},
			assert: func(t *testing.T, err error) {
				assert.NoError(t, err)
			},
		},
		{
			name: "error multiple confirmations",
			action: func(t *testing.T, msg *Message) error {
				err := msg.Acknowledge(true)
				assert.NoError(t, err)

				return msg.Acknowledge(true)
			},
			assert: func(t *testing.T, err error) {
				assert.ErrorIs(t, err, errors.ErrMessageAlreadyAcknowledged)
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			var msg Message
			err := tc.action(t, &msg)
			tc.assert(t, err)
		})
	}
}