snsmock

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2022 License: MIT Imports: 3 Imported by: 0

README

SNS Client

Usage

// main.go
package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sns"
)

type snsClient interface {
	ListTopics(ctx context.Context, params *sns.ListTopicsInput, optFns ...func(*sns.Options)) (*sns.ListTopicsOutput, error)
}

func main() {
	cfg, _ := config.LoadDefaultConfig(context.Background())
	client := sns.NewFromConfig(cfg)

	topics, _ := getTopics(context.Background(), client)
	fmt.Printf("%#v", topics)
}

func getTopics(ctx context.Context, c snsClient) ([]string, error) {
	topics, err := c.ListTopics(ctx, &sns.ListTopicsInput{})
	if err != nil {
		return nil, err
	}

	var topicsARNs []string
	for _, t := range topics.Topics {
		topicsARNs = append(topicsARNs, *t.TopicArn)
	}
	return topicsARNs, nil
}
// main_test.go
package main

import (
	"context"
	"testing"

	"github.com/aws/aws-sdk-go-v2/service/sns"
	"github.com/aws/aws-sdk-go-v2/service/sns/types"
	"github.com/gvre/awsmock-v2/snsmock"
	"github.com/stretchr/testify/mock"
)

func TestGetTopics(t *testing.T) {
	topicsARNs := []types.Topic{
		{
			TopicArn: new(string),
		},
	}
	client := new(snsmock.Client)
	client.On("ListTopics", mock.Anything, mock.Anything, mock.Anything).Return(&sns.ListTopicsOutput{
		Topics: topicsARNs,
	}, nil)

	topics, _ := getTopics(context.Background(), client)

	if ntopics, nTopicsARNs := len(topics), len(topicsARNs); ntopics != nTopicsARNs {
		t.Errorf("Invalid number of topics, got: %v, want: %v", ntopics, nTopicsARNs)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	mock.Mock
}

Client provides the API client to mock operations call for Amazon SNS Service.

func (*Client) AddPermission

func (c *Client) AddPermission(ctx context.Context, params *sns.AddPermissionInput, optFns ...func(*sns.Options)) (*sns.AddPermissionOutput, error)

AddPermission mock.

func (*Client) CheckIfPhoneNumberIsOptedOut

func (c *Client) CheckIfPhoneNumberIsOptedOut(ctx context.Context, params *sns.CheckIfPhoneNumberIsOptedOutInput, optFns ...func(*sns.Options)) (*sns.CheckIfPhoneNumberIsOptedOutOutput, error)

CheckIfPhoneNumberIsOptedOut mock.

func (*Client) ConfirmSubscription

func (c *Client) ConfirmSubscription(ctx context.Context, params *sns.ConfirmSubscriptionInput, optFns ...func(*sns.Options)) (*sns.ConfirmSubscriptionOutput, error)

ConfirmSubscription mock.

func (*Client) CreatePlatformApplication

func (c *Client) CreatePlatformApplication(ctx context.Context, params *sns.CreatePlatformApplicationInput, optFns ...func(*sns.Options)) (*sns.CreatePlatformApplicationOutput, error)

CreatePlatformApplication mock.

func (*Client) CreatePlatformEndpoint

func (c *Client) CreatePlatformEndpoint(ctx context.Context, params *sns.CreatePlatformEndpointInput, optFns ...func(*sns.Options)) (*sns.CreatePlatformEndpointOutput, error)

CreatePlatformEndpoint mock.

func (*Client) CreateSMSSandboxPhoneNumber

func (c *Client) CreateSMSSandboxPhoneNumber(ctx context.Context, params *sns.CreateSMSSandboxPhoneNumberInput, optFns ...func(*sns.Options)) (*sns.CreateSMSSandboxPhoneNumberOutput, error)

CreateSMSSandboxPhoneNumber mock.

func (*Client) CreateTopic

func (c *Client) CreateTopic(ctx context.Context, params *sns.CreateTopicInput, optFns ...func(*sns.Options)) (*sns.CreateTopicOutput, error)

CreateTopic mock.

func (*Client) DeleteEndpoint

func (c *Client) DeleteEndpoint(ctx context.Context, params *sns.DeleteEndpointInput, optFns ...func(*sns.Options)) (*sns.DeleteEndpointOutput, error)

DeleteEndpoint mock.

func (*Client) DeletePlatformApplication

func (c *Client) DeletePlatformApplication(ctx context.Context, params *sns.DeletePlatformApplicationInput, optFns ...func(*sns.Options)) (*sns.DeletePlatformApplicationOutput, error)

DeletePlatformApplication mock.

func (*Client) DeleteSMSSandboxPhoneNumber

func (c *Client) DeleteSMSSandboxPhoneNumber(ctx context.Context, params *sns.DeleteSMSSandboxPhoneNumberInput, optFns ...func(*sns.Options)) (*sns.DeleteSMSSandboxPhoneNumberOutput, error)

DeleteSMSSandboxPhoneNumber mock.

func (*Client) DeleteTopic

func (c *Client) DeleteTopic(ctx context.Context, params *sns.DeleteTopicInput, optFns ...func(*sns.Options)) (*sns.DeleteTopicOutput, error)

DeleteTopic mock.

func (*Client) GetEndpointAttributes

func (c *Client) GetEndpointAttributes(ctx context.Context, params *sns.GetEndpointAttributesInput, optFns ...func(*sns.Options)) (*sns.GetEndpointAttributesOutput, error)

GetEndpointAttributes mock.

func (*Client) GetPlatformApplicationAttributes

func (c *Client) GetPlatformApplicationAttributes(ctx context.Context, params *sns.GetPlatformApplicationAttributesInput, optFns ...func(*sns.Options)) (*sns.GetPlatformApplicationAttributesOutput, error)

GetPlatformApplicationAttributes mock.

func (*Client) GetSMSAttributes

func (c *Client) GetSMSAttributes(ctx context.Context, params *sns.GetSMSAttributesInput, optFns ...func(*sns.Options)) (*sns.GetSMSAttributesOutput, error)

GetSMSAttributes mock.

func (*Client) GetSMSSandboxAccountStatus

func (c *Client) GetSMSSandboxAccountStatus(ctx context.Context, params *sns.GetSMSSandboxAccountStatusInput, optFns ...func(*sns.Options)) (*sns.GetSMSSandboxAccountStatusOutput, error)

GetSMSSandboxAccountStatus mock.

func (*Client) GetSubscriptionAttributes

func (c *Client) GetSubscriptionAttributes(ctx context.Context, params *sns.GetSubscriptionAttributesInput, optFns ...func(*sns.Options)) (*sns.GetSubscriptionAttributesOutput, error)

GetSubscriptionAttributes mock.

func (*Client) GetTopicAttributes

func (c *Client) GetTopicAttributes(ctx context.Context, params *sns.GetTopicAttributesInput, optFns ...func(*sns.Options)) (*sns.GetTopicAttributesOutput, error)

GetTopicAttributes mock.

func (*Client) ListEndpointsByPlatformApplication

func (c *Client) ListEndpointsByPlatformApplication(ctx context.Context, params *sns.ListEndpointsByPlatformApplicationInput, optFns ...func(*sns.Options)) (*sns.ListEndpointsByPlatformApplicationOutput, error)

ListEndpointsByPlatformApplication mock.

func (*Client) ListOriginationNumbers

func (c *Client) ListOriginationNumbers(ctx context.Context, params *sns.ListOriginationNumbersInput, optFns ...func(*sns.Options)) (*sns.ListOriginationNumbersOutput, error)

ListOriginationNumbers mock.

func (*Client) ListPhoneNumbersOptedOut

func (c *Client) ListPhoneNumbersOptedOut(ctx context.Context, params *sns.ListPhoneNumbersOptedOutInput, optFns ...func(*sns.Options)) (*sns.ListPhoneNumbersOptedOutOutput, error)

ListPhoneNumbersOptedOut mock.

func (*Client) ListPlatformApplications

func (c *Client) ListPlatformApplications(ctx context.Context, params *sns.ListPlatformApplicationsInput, optFns ...func(*sns.Options)) (*sns.ListPlatformApplicationsOutput, error)

ListPlatformApplications mock.

func (*Client) ListSMSSandboxPhoneNumbers

func (c *Client) ListSMSSandboxPhoneNumbers(ctx context.Context, params *sns.ListSMSSandboxPhoneNumbersInput, optFns ...func(*sns.Options)) (*sns.ListSMSSandboxPhoneNumbersOutput, error)

ListSMSSandboxPhoneNumbers mock.

func (*Client) ListSubscriptions

func (c *Client) ListSubscriptions(ctx context.Context, params *sns.ListSubscriptionsInput, optFns ...func(*sns.Options)) (*sns.ListSubscriptionsOutput, error)

ListSubscriptions mock.

func (*Client) ListSubscriptionsByTopic

func (c *Client) ListSubscriptionsByTopic(ctx context.Context, params *sns.ListSubscriptionsByTopicInput, optFns ...func(*sns.Options)) (*sns.ListSubscriptionsByTopicOutput, error)

ListSubscriptionsByTopic mock.

func (*Client) ListTagsForResource

func (c *Client) ListTagsForResource(ctx context.Context, params *sns.ListTagsForResourceInput, optFns ...func(*sns.Options)) (*sns.ListTagsForResourceOutput, error)

ListTagsForResource mock.

func (*Client) ListTopics

func (c *Client) ListTopics(ctx context.Context, params *sns.ListTopicsInput, optFns ...func(*sns.Options)) (*sns.ListTopicsOutput, error)

ListTopics mock.

func (*Client) OptInPhoneNumber

func (c *Client) OptInPhoneNumber(ctx context.Context, params *sns.OptInPhoneNumberInput, optFns ...func(*sns.Options)) (*sns.OptInPhoneNumberOutput, error)

OptInPhoneNumber mock.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error)

Publish mock.

func (*Client) PublishBatch

func (c *Client) PublishBatch(ctx context.Context, params *sns.PublishBatchInput, optFns ...func(*sns.Options)) (*sns.PublishBatchOutput, error)

PublishBatch mock.

func (*Client) RemovePermission

func (c *Client) RemovePermission(ctx context.Context, params *sns.RemovePermissionInput, optFns ...func(*sns.Options)) (*sns.RemovePermissionOutput, error)

RemovePermission mock.

func (*Client) SetEndpointAttributes

func (c *Client) SetEndpointAttributes(ctx context.Context, params *sns.SetEndpointAttributesInput, optFns ...func(*sns.Options)) (*sns.SetEndpointAttributesOutput, error)

SetEndpointAttributes mock.

func (*Client) SetPlatformApplicationAttributes

func (c *Client) SetPlatformApplicationAttributes(ctx context.Context, params *sns.SetPlatformApplicationAttributesInput, optFns ...func(*sns.Options)) (*sns.SetPlatformApplicationAttributesOutput, error)

SetPlatformApplicationAttributes mock.

func (*Client) SetSMSAttributes

func (c *Client) SetSMSAttributes(ctx context.Context, params *sns.SetSMSAttributesInput, optFns ...func(*sns.Options)) (*sns.SetSMSAttributesOutput, error)

SetSMSAttributes mock.

func (*Client) SetSubscriptionAttributes

func (c *Client) SetSubscriptionAttributes(ctx context.Context, params *sns.SetSubscriptionAttributesInput, optFns ...func(*sns.Options)) (*sns.SetSubscriptionAttributesOutput, error)

SetSubscriptionAttributes mock.

func (*Client) SetTopicAttributes

func (c *Client) SetTopicAttributes(ctx context.Context, params *sns.SetTopicAttributesInput, optFns ...func(*sns.Options)) (*sns.SetTopicAttributesOutput, error)

SetTopicAttributes mock.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, params *sns.SubscribeInput, optFns ...func(*sns.Options)) (*sns.SubscribeOutput, error)

Subscribe mock.

func (*Client) TagResource

func (c *Client) TagResource(ctx context.Context, params *sns.TagResourceInput, optFns ...func(*sns.Options)) (*sns.TagResourceOutput, error)

TagResource mock.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, params *sns.UnsubscribeInput, optFns ...func(*sns.Options)) (*sns.UnsubscribeOutput, error)

Unsubscribe mock.

func (*Client) UntagResource

func (c *Client) UntagResource(ctx context.Context, params *sns.UntagResourceInput, optFns ...func(*sns.Options)) (*sns.UntagResourceOutput, error)

UntagResource mock.

func (*Client) VerifySMSSandboxPhoneNumber

func (c *Client) VerifySMSSandboxPhoneNumber(ctx context.Context, params *sns.VerifySMSSandboxPhoneNumberInput, optFns ...func(*sns.Options)) (*sns.VerifySMSSandboxPhoneNumberOutput, error)

VerifySMSSandboxPhoneNumber mock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL