-
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
20c9e6c
commit 1fd4ded
Showing
13 changed files
with
289 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gosqs | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"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 DeleteQueueV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewDeleteQueueRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - DeleteQueueV1") | ||
return createErrorResponseV1(ErrInvalidParameterValue.Type) | ||
} | ||
|
||
uriSegments := strings.Split(requestBody.QueueUrl, "/") | ||
queueName := uriSegments[len(uriSegments)-1] | ||
|
||
log.Infof("Deleting Queue: %s", queueName) | ||
|
||
app.SyncQueues.Lock() | ||
delete(app.SyncQueues.Queues, queueName) | ||
app.SyncQueues.Unlock() | ||
|
||
respStruct := models.DeleteQueueResponse{ | ||
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,91 @@ | ||
package gosqs | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/Admiral-Piett/goaws/app/conf" | ||
"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" | ||
) | ||
|
||
func TestDeleteQueueV1_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.DeleteQueueRequest) | ||
*v = models.DeleteQueueRequest{ | ||
QueueUrl: fmt.Sprintf("%s/%s", fixtures.BASE_URL, "unit-queue1"), | ||
} | ||
return true | ||
} | ||
|
||
expectedResponse := models.DeleteQueueResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Metadata: models.BASE_RESPONSE_METADATA, | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := DeleteQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, expectedResponse, response) | ||
|
||
_, ok := app.SyncQueues.Queues["unit-queue1"] | ||
assert.False(t, ok) | ||
} | ||
|
||
func TestDeleteQueueV1_success_unknown_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.DeleteQueueRequest) | ||
*v = models.DeleteQueueRequest{ | ||
QueueUrl: fmt.Sprintf("%s/%s", fixtures.BASE_URL, "unknown-queue1"), | ||
} | ||
return true | ||
} | ||
|
||
expectedResponse := models.DeleteQueueResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Metadata: models.BASE_RESPONSE_METADATA, | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := DeleteQueueV1(r) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, expectedResponse, response) | ||
} | ||
|
||
func TestDeleteQueueV1_success_invalid_request(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, _ := DeleteQueueV1(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
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.