-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3d5762
commit fcdd208
Showing
12 changed files
with
321 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gosqs | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func PurgeQueueV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewPurgeQueueRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - PurgeQueueV1") | ||
return createErrorResponseV1(ErrInvalidParameterValue.Type) | ||
} | ||
|
||
uriSegments := strings.Split(requestBody.QueueUrl, "/") | ||
queueName := uriSegments[len(uriSegments)-1] | ||
|
||
app.SyncQueues.Lock() | ||
defer app.SyncQueues.Unlock() | ||
if _, ok := app.SyncQueues.Queues[queueName]; !ok { | ||
log.Errorf("Purge Queue: %s, queue does not exist!!!", queueName) | ||
return createErrorResponseV1("QueueNotFound") | ||
} | ||
|
||
log.Infof("Purging Queue: %s", queueName) | ||
app.SyncQueues.Queues[queueName].Messages = nil | ||
app.SyncQueues.Queues[queueName].Duplicates = make(map[string]time.Time) | ||
|
||
respStruct := models.PurgeQueueResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Metadata: models.BASE_RESPONSE_METADATA, | ||
} | ||
return http.StatusOK, respStruct | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package gosqs | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Admiral-Piett/goaws/app/conf" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/fixtures" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPurgeQueueV1_success(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
utils.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.PurgeQueueRequest) | ||
*v = models.PurgeQueueRequest{ | ||
QueueUrl: fmt.Sprintf("%s/%s", fixtures.BASE_URL, "unit-queue1"), | ||
} | ||
return true | ||
} | ||
|
||
// Put a message on the queue | ||
targetQueue := app.SyncQueues.Queues["unit-queue1"] | ||
app.SyncQueues.Lock() | ||
targetQueue.Messages = []app.Message{app.Message{}} | ||
targetQueue.Duplicates = map[string]time.Time{ | ||
"dedupe-id": time.Now(), | ||
} | ||
app.SyncQueues.Unlock() | ||
|
||
expectedResponse := models.PurgeQueueResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Metadata: models.BASE_RESPONSE_METADATA, | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := PurgeQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, expectedResponse, response) | ||
|
||
assert.Nil(t, targetQueue.Messages) | ||
assert.Equal(t, map[string]time.Time{}, targetQueue.Duplicates) | ||
} | ||
|
||
func TestPurgeQueueV1_success_no_messages_on_queue(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
utils.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.PurgeQueueRequest) | ||
*v = models.PurgeQueueRequest{ | ||
QueueUrl: fmt.Sprintf("%s/%s", fixtures.BASE_URL, "unit-queue1"), | ||
} | ||
return true | ||
} | ||
|
||
expectedResponse := models.PurgeQueueResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Metadata: models.BASE_RESPONSE_METADATA, | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := PurgeQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, expectedResponse, response) | ||
|
||
targetQueue := app.SyncQueues.Queues["unit-queue1"] | ||
assert.Nil(t, targetQueue.Messages) | ||
assert.Equal(t, map[string]time.Time{}, targetQueue.Duplicates) | ||
} | ||
|
||
func TestPurgeQueueV1_request_transformer_error(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
utils.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
return false | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, _ := PurgeQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} | ||
|
||
func TestPurgeQueueV1_requested_queue_does_not_exist(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
utils.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.PurgeQueueRequest) | ||
*v = models.PurgeQueueRequest{ | ||
QueueUrl: fmt.Sprintf("%s/%s", fixtures.BASE_URL, "garbage"), | ||
} | ||
return true | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, _ := PurgeQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.