Skip to content

Commit

Permalink
[SQS] Add sqs prefix setter (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
gotokatsuya authored and evalphobia committed Apr 16, 2018
1 parent fc92ea3 commit 47003b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sqs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (svc *SQS) SetLogger(logger log.Logger) {
svc.logger = logger
}

// SetPrefix sets prefix.
func (svc *SQS) SetPrefix(prefix string) {
svc.prefix = prefix
}

// GetQueue gets SQS Queue.
func (svc *SQS) GetQueue(name string) (*Queue, error) {
queueName := svc.prefix + name
Expand Down
27 changes: 27 additions & 0 deletions sqs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,30 @@ func TestIsExistQueue(t *testing.T) {
assert.NoError(err)
assert.False(has)
}

func TestSetPrefix(t *testing.T) {
assert := assert.New(t)
svc := getTestClient(t)

svc.SetPrefix("prefix_")
ok, _ := svc.IsExistQueue("test")
if !ok {
svc.CreateQueueWithName("test")
}
// No error
q, err := svc.GetQueue("test")
assert.NoError(err)
assert.NotNil(q)

// Has error
svc.SetPrefix("prefix2_")
q, err = svc.GetQueue("test")
assert.Error(err)
assert.Nil(q)

// No error
svc.SetPrefix("prefix_")
q, err = svc.GetQueue("test")
assert.NoError(err)
assert.NotNil(q)
}

0 comments on commit 47003b8

Please sign in to comment.