-
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
fcdd208
commit a65cc66
Showing
9 changed files
with
308 additions
and
36 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" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func GetQueueUrlV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
|
||
requestBody := models.NewGetQueueUrlRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - GetQueueUrlV1") | ||
return createErrorResponseV1(ErrInvalidParameterValue.Type) | ||
} | ||
|
||
queueName := requestBody.QueueName | ||
if _, ok := app.SyncQueues.Queues[queueName]; !ok { | ||
log.Error("Get Queue URL:", queueName, ", queue does not exist!!!") | ||
return createErrorResponseV1("QueueNotFound") | ||
} | ||
|
||
queue := app.SyncQueues.Queues[queueName] | ||
log.Debug("Get Queue URL:", queue.Name) | ||
|
||
result := models.GetQueueUrlResult{QueueUrl: queue.URL} | ||
respStruct := models.GetQueueUrlResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Result: result, | ||
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,102 @@ | ||
package gosqs | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"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" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetQueueUrlV1_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.GetQueueUrlRequest) | ||
*v = models.GetQueueUrlRequest{ | ||
QueueName: "unit-queue1", | ||
QueueOwnerAWSAccountId: "fugafuga", | ||
} | ||
return true | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo( | ||
"POST", | ||
"/", | ||
nil, | ||
true) | ||
code, response := GetQueueUrlV1(r) | ||
|
||
get_queue_url_response := response.(models.GetQueueUrlResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Contains(t, get_queue_url_response.Result.QueueUrl, fmt.Sprintf("%s/%s", fixtures.BASE_URL, "unit-queue1")) | ||
|
||
} | ||
|
||
func TestGetQueueUrlV1_error_no_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.GetQueueUrlRequest) | ||
*v = models.GetQueueUrlRequest{ | ||
QueueName: "not-exist-unit-queue1", | ||
QueueOwnerAWSAccountId: "fugafuga", | ||
} | ||
return true | ||
} | ||
|
||
_, r := utils.GenerateRequestInfo( | ||
"POST", | ||
"/", | ||
nil, | ||
true) | ||
code, response := GetQueueUrlV1(r) | ||
|
||
expected := models.ErrorResult{ | ||
Type: "Not Found", | ||
Code: "AWS.SimpleQueueService.NonExistentQueue", | ||
Message: "The specified queue does not exist for this wsdl version.", | ||
} | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
assert.Equal(t, response.GetResult().(models.ErrorResult), expected) | ||
} | ||
|
||
func TestGetQueueUrlV1_error_request_transformer(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, _ := GetQueueUrlV1(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
Oops, something went wrong.