diff --git a/aws/s3/s3.go b/aws/s3/s3.go index c418c31..f193d93 100644 --- a/aws/s3/s3.go +++ b/aws/s3/s3.go @@ -271,11 +271,10 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e return err } -// checks if the given S3 bucket exists. -func (s *S3) CheckBucketExists(bucketName string) error { - // Check if the bucket exists. +// checks if the given S3 bucket exists and is accessible. +func (s *S3) CheckBucket(bucket string) error { _, err := s.client.HeadBucket(context.TODO(), &s3.HeadBucketInput{ - Bucket: aws.String(bucketName), + Bucket: aws.String(bucket), }) return err diff --git a/aws/s3/s3_integration_test.go b/aws/s3/s3_integration_test.go index 5ebfded..6780961 100644 --- a/aws/s3/s3_integration_test.go +++ b/aws/s3/s3_integration_test.go @@ -204,6 +204,24 @@ func awsCmdGetTestObject() string { // THE TESTS +func TestCheckBucket(t *testing.T) { + setup() + defer teardown() + + // test + client, err := New() + assert.Nil(t, err) + //test existing bucket + err = client.CheckBucket(testBucket) + assert.Nil(t, err) + + //test none existing bucket + testBucket1 := "test1" + err = client.CheckBucket(testBucket1) + assert.NotNil(t, err) + +} + func TestCreateS3ClientAndReady(t *testing.T) { // ARRANGE setup() diff --git a/aws/sns/sns.go b/aws/sns/sns.go index ffca11c..948fdbd 100644 --- a/aws/sns/sns.go +++ b/aws/sns/sns.go @@ -116,6 +116,14 @@ func (s *SNS) DeleteTopic(topicArn string) error { return err } +// checks if an SNS topic exists and is accessible given its ARN. +func (s *SNS) CheckTopic(topicArn string) error { + _, err := s.client.GetTopicAttributes(context.TODO(), &sns.GetTopicAttributesInput{ + TopicArn: aws.String(topicArn), + }) + return err +} + // SubscribeQueue subscribes an SQS queue to an SNS topic. func (s *SNS) SubscribeQueue(topicArn string, queueArn string) (string, error) { output, err := s.client.Subscribe(context.TODO(), &sns.SubscribeInput{ diff --git a/aws/sns/sns_integration_test.go b/aws/sns/sns_integration_test.go index bf80b7f..ae1f796 100644 --- a/aws/sns/sns_integration_test.go +++ b/aws/sns/sns_integration_test.go @@ -57,6 +57,26 @@ func teardown(queueArn, topicArn string) { os.Unsetenv("AWS_ENDPOINT_URL") } +func TestCheckTopic(t *testing.T) { + _, topicArn := setup(false, true) + defer teardown("", topicArn) + + client, err := New() + ready := client.Ready() + // ASSERT + assert.Nil(t, err) + assert.True(t, ready) + + //check existing topic + err = client.CheckTopic(topicArn) + assert.Nil(t, err) + + //check none existing topic + err = client.CheckTopic(topicArn + "_1") + assert.NotNil(t, err) + +} + func TestSNSNewAndReady(t *testing.T) { // ARRANGE setup(false, false) diff --git a/aws/sqs/sqs.go b/aws/sqs/sqs.go index d02fac0..7e61364 100644 --- a/aws/sqs/sqs.go +++ b/aws/sqs/sqs.go @@ -320,13 +320,15 @@ func (s *SQS) CreateQueue(queueName string, isFifoQueue bool) (string, error) { return aws.ToString(queue.QueueUrl), err } -// checks if the given SQS queue exists. -func (s *SQS) CheckQueueExists(queueName string) error { - // Check if the queue exists. - _, err := s.client.GetQueueUrl(context.TODO(), &sqs.GetQueueUrlInput{ - QueueName: aws.String(queueName), - }) - +// checks if the given SQS queue exists and is accessible. +func (s *SQS) CheckQueue(queueUrl string) error { + params := sqs.GetQueueAttributesInput{ + QueueUrl: aws.String(queueUrl), + AttributeNames: []types.QueueAttributeName{ + types.QueueAttributeNameAll, + }, + } + _, err := s.client.GetQueueAttributes(context.TODO(), ¶ms) return err } diff --git a/aws/sqs/sqs_integration_test.go b/aws/sqs/sqs_integration_test.go index 71e7b2c..3ef5fdb 100644 --- a/aws/sqs/sqs_integration_test.go +++ b/aws/sqs/sqs_integration_test.go @@ -182,6 +182,30 @@ func awsCmdCheckSQSAttribute(url, attribute, expectedValue string) bool { return false } +func TestCheckQueue(t *testing.T) { + // ARRANGE + setup() + defer teardown() + + client, err := New() + + // ASSERT + assert.Nil(t, err) + + //test existing queue + queue, err := client.GetQueueUrl(testQueue) + + assert.Nil(t, err) + + err = client.CheckQueue(queue) + assert.Nil(t, err) + + //test none existing queue + err = client.CheckQueue(queue + "_1") + assert.NotNil(t, err) + +} + func TestSQSNewAndReady(t *testing.T) { // ARRANGE setup()