-
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
29b45a3
commit 85b0f0b
Showing
2 changed files
with
111 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package gosqs | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSendMessage_MaximumMessageSize_Success(t *testing.T) { | ||
req, err := http.NewRequest("POST", "/", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app.SyncQueues.Queues["test_max_message_size"] = | ||
&app.Queue{Name: "test_max_message_size", MaximumMessageSize: 100} | ||
|
||
form := url.Values{} | ||
form.Add("Action", "SendMessage") | ||
form.Add("QueueUrl", "http://localhost:4100/queue/test_max_message_size") | ||
form.Add("MessageBody", "test%20message%20body%201") | ||
form.Add("Version", "2012-11-05") | ||
req.PostForm = form | ||
|
||
status, response := SendMessageV1(req) | ||
|
||
// Check the status code is what we expect. | ||
if status != http.StatusOK { | ||
t.Errorf("handler returned wrong status code: got %v want %v", | ||
status, http.StatusOK) | ||
} | ||
|
||
// Check the response body is what we expect. | ||
sendMessageResponse, ok := response.(models.SendMessageResponse) | ||
assert.True(t, ok) | ||
if len(sendMessageResponse.Result.MD5OfMessageBody) == 0 { | ||
t.Errorf("handler returned unexpected body: got %v", | ||
sendMessageResponse.Result) | ||
} | ||
} | ||
|
||
func TestSendMessage_MaximumMessageSize_MessageTooBig(t *testing.T) { | ||
req, err := http.NewRequest("POST", "/", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app.SyncQueues.Queues["test_max_message_size"] = | ||
&app.Queue{Name: "test_max_message_size", MaximumMessageSize: 10} | ||
|
||
form := url.Values{} | ||
form.Add("Action", "SendMessage") | ||
form.Add("QueueUrl", "http://localhost:4100/queue/test_max_message_size") | ||
form.Add("MessageBody", "test%20message%20body%201") | ||
form.Add("Version", "2012-11-05") | ||
req.PostForm = form | ||
|
||
status, response := SendMessageV1(req) | ||
|
||
// Check the status code is what we expect. | ||
if status != http.StatusBadRequest { | ||
t.Errorf("handler returned wrong status code: got %v want %v", | ||
status, http.StatusBadRequest) | ||
} | ||
|
||
// Check the response body is what we expect. | ||
errorResponse, ok := response.(models.ErrorResponse) | ||
assert.True(t, ok) | ||
expected := "MessageTooBig" | ||
if errorResponse.Result.Type != expected { | ||
t.Errorf("handler returned unexpected body: got %v want %v", | ||
errorResponse.Result.Type, expected) | ||
} | ||
} | ||
|
||
func TestSendQueue_POST_NonExistant(t *testing.T) { | ||
// Create a request to pass to our handler. We don't have any query parameters for now, so we'll | ||
// pass 'nil' as the third parameter. | ||
req, err := http.NewRequest("POST", "/", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
form := url.Values{} | ||
form.Add("Action", "SendMessage") | ||
form.Add("QueueUrl", "http://localhost:4100/queue/NON-EXISTANT") | ||
form.Add("MessageBody", "Test123") | ||
form.Add("Version", "2012-11-05") | ||
req.PostForm = form | ||
|
||
status, response := SendMessageV1(req) | ||
|
||
// Check the status code is what we expect. | ||
if status != http.StatusBadRequest { | ||
t.Errorf("handler returned wrong status code: got %v want %v", | ||
status, http.StatusBadRequest) | ||
} | ||
|
||
// Check the response body is what we expect. | ||
errorResponse, ok := response.(models.ErrorResponse) | ||
assert.True(t, ok) | ||
expected := "Not Found" | ||
if errorResponse.Result.Type != expected { | ||
t.Errorf("handler returned unexpected body: got %v want %v", | ||
errorResponse.Result.Type, expected) | ||
} | ||
} |