Skip to content

Commit

Permalink
update per review, add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpeng committed Nov 27, 2024
1 parent 56c71e3 commit 0d06f95
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
5 changes: 2 additions & 3 deletions aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,9 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
}

// checks if the given S3 bucket exists.
func (s *S3) CheckBucketExists(bucketName string) error {
// Check if the bucket exists.
func (s *S3) CheckBucketExists(bucket string) error {
_, err := s.client.HeadBucket(context.TODO(), &s3.HeadBucketInput{
Bucket: aws.String(bucketName),
Bucket: aws.String(bucket),
})

return err
Expand Down
18 changes: 18 additions & 0 deletions aws/s3/s3_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ func awsCmdGetTestObject() string {

// THE TESTS

func TestCheckBucketExists(t *testing.T) {
setup()
defer teardown()

// test
client, err := New()
assert.Nil(t, err)
//test existing bucket
err = client.CheckBucketExists(testBucket)
assert.Nil(t, err)

//test none existing bucket
testBucket1 := "test1"
err = client.CheckBucketExists(testBucket1)
assert.NotNil(t, err)

}

func TestCreateS3ClientAndReady(t *testing.T) {
// ARRANGE
setup()
Expand Down
14 changes: 8 additions & 6 deletions aws/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ func (s *SQS) CreateQueue(queueName string, isFifoQueue bool) (string, error) {
}

// 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),
})

func (s *SQS) CheckQueueExists(queueUrl string) error {
params := sqs.GetQueueAttributesInput{
QueueUrl: aws.String(queueUrl),
AttributeNames: []types.QueueAttributeName{
types.QueueAttributeNameAll,
},
}
_, err := s.client.GetQueueAttributes(context.TODO(), &params)
return err
}

Expand Down
24 changes: 24 additions & 0 deletions aws/sqs/sqs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ func awsCmdCheckSQSAttribute(url, attribute, expectedValue string) bool {
return false
}

func TestCheckQueueExists(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.CheckQueueExists(queue)
assert.Nil(t, err)

//test none existing queue
err = client.CheckQueueExists(queue + "_1")
assert.NotNil(t, err)

}

func TestSQSNewAndReady(t *testing.T) {
// ARRANGE
setup()
Expand Down

0 comments on commit 0d06f95

Please sign in to comment.