1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-11-28 08:39:13 +02:00

test(go): allow for parallel tests

This commit is contained in:
Niko Köser 2022-04-22 20:45:29 +02:00
parent b50efdf40b
commit 4585e9fc94
No known key found for this signature in database
GPG Key ID: F3F28C118DAA6375
6 changed files with 35 additions and 3 deletions

View File

@ -25,7 +25,8 @@ type SNSSendMessageClient struct {
// SendMessage Client specific for SNS using aws sdk v2. // SendMessage Client specific for SNS using aws sdk v2.
func (s SNSSendMessageClient) SendMessage(ctx context.Context, func (s SNSSendMessageClient) SendMessage(ctx context.Context,
params *sns.PublishInput, params *sns.PublishInput,
optFns ...func(*sns.Options)) (*sns.PublishOutput, error) { optFns ...func(*sns.Options),
) (*sns.PublishOutput, error) {
return s.client.Publish(ctx, params, optFns...) return s.client.Publish(ctx, params, optFns...)
} }

View File

@ -16,12 +16,15 @@ type SNSSendMessageMock struct {
func (m *SNSSendMessageMock) SendMessage(ctx context.Context, func (m *SNSSendMessageMock) SendMessage(ctx context.Context,
params *sns.PublishInput, params *sns.PublishInput,
optFns ...func(*sns.Options)) (*sns.PublishOutput, error) { optFns ...func(*sns.Options),
) (*sns.PublishOutput, error) {
args := m.Called(ctx, params, optFns) args := m.Called(ctx, params, optFns)
return args.Get(0).(*sns.PublishOutput), args.Error(1) return args.Get(0).(*sns.PublishOutput), args.Error(1)
} }
func TestAddReceivers(t *testing.T) { func TestAddReceivers(t *testing.T) {
t.Parallel()
amazonSNS, err := New("", "", "") amazonSNS, err := New("", "", "")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -30,6 +33,8 @@ func TestAddReceivers(t *testing.T) {
} }
func TestSendMessageWithNoTopicsConfigured(t *testing.T) { func TestSendMessageWithNoTopicsConfigured(t *testing.T) {
t.Parallel()
mockSns := new(SNSSendMessageMock) mockSns := new(SNSSendMessageMock)
amazonSNS := AmazonSNS{ amazonSNS := AmazonSNS{
sendMessageClient: mockSns, sendMessageClient: mockSns,
@ -41,6 +46,8 @@ func TestSendMessageWithNoTopicsConfigured(t *testing.T) {
} }
func TestSendMessageWithSucessAndOneTopicCOnfigured(t *testing.T) { func TestSendMessageWithSucessAndOneTopicCOnfigured(t *testing.T) {
t.Parallel()
mockSns := new(SNSSendMessageMock) mockSns := new(SNSSendMessageMock)
output := sns.PublishOutput{} output := sns.PublishOutput{}
mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything). mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything).
@ -58,6 +65,8 @@ func TestSendMessageWithSucessAndOneTopicCOnfigured(t *testing.T) {
} }
func TestSendMessageWithSucessAndTwoTopicCOnfigured(t *testing.T) { func TestSendMessageWithSucessAndTwoTopicCOnfigured(t *testing.T) {
t.Parallel()
mockSns := new(SNSSendMessageMock) mockSns := new(SNSSendMessageMock)
output := sns.PublishOutput{} output := sns.PublishOutput{}
mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything). mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything).
@ -78,6 +87,8 @@ func TestSendMessageWithSucessAndTwoTopicCOnfigured(t *testing.T) {
} }
func TestSendMessageWithErrorAndOneQueueConfiguredShouldReturnError(t *testing.T) { func TestSendMessageWithErrorAndOneQueueConfiguredShouldReturnError(t *testing.T) {
t.Parallel()
mockSns := new(SNSSendMessageMock) mockSns := new(SNSSendMessageMock)
output := sns.PublishOutput{} output := sns.PublishOutput{}
mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything). mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything).
@ -97,6 +108,8 @@ func TestSendMessageWithErrorAndOneQueueConfiguredShouldReturnError(t *testing.T
} }
func TestSendMessageWithErrorAndTwoQueueConfiguredShouldReturnErrorOnFirst(t *testing.T) { func TestSendMessageWithErrorAndTwoQueueConfiguredShouldReturnErrorOnFirst(t *testing.T) {
t.Parallel()
mockSns := new(SNSSendMessageMock) mockSns := new(SNSSendMessageMock)
output := sns.PublishOutput{} output := sns.PublishOutput{}
mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything). mockSns.On("SendMessage", mock.Anything, mock.Anything, mock.Anything).

View File

@ -5,11 +5,13 @@ import (
"errors" "errors"
"testing" "testing"
plivo "github.com/plivo/plivo-go/v7" "github.com/plivo/plivo-go/v7"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
// nil ClientOptions // nil ClientOptions
@ -34,6 +36,8 @@ func TestNew(t *testing.T) {
} }
func TestAddReceivers(t *testing.T) { func TestAddReceivers(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc, err := New(&ClientOptions{}, &MessageOptions{Source: "12345"}) svc, err := New(&ClientOptions{}, &MessageOptions{Source: "12345"})
@ -47,6 +51,8 @@ func TestAddReceivers(t *testing.T) {
} }
func TestSend(t *testing.T) { func TestSend(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc, err := New(&ClientOptions{}, &MessageOptions{Source: "12345"}) svc, err := New(&ClientOptions{}, &MessageOptions{Source: "12345"})

View File

@ -10,6 +10,8 @@ import (
) )
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
// Test creating a local writer with invalid log priority. // Test creating a local writer with invalid log priority.
@ -38,6 +40,8 @@ func TestNew(t *testing.T) {
} }
func TestSend(t *testing.T) { func TestSend(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
ctx := context.Background() ctx := context.Background()

View File

@ -10,6 +10,8 @@ import (
) )
func TestAddReceivers(t *testing.T) { func TestAddReceivers(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc := &Service{ svc := &Service{
@ -22,6 +24,8 @@ func TestAddReceivers(t *testing.T) {
} }
func TestSend(t *testing.T) { func TestSend(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc := &Service{ svc := &Service{

View File

@ -10,6 +10,8 @@ import (
) )
func TestAddReceivers(t *testing.T) { func TestAddReceivers(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc := &Service{ svc := &Service{
@ -22,6 +24,8 @@ func TestAddReceivers(t *testing.T) {
} }
func TestSend(t *testing.T) { func TestSend(t *testing.T) {
t.Parallel()
assert := require.New(t) assert := require.New(t)
svc := &Service{ svc := &Service{