Merge pull request #15 from Skarlso/master

Added new tests to addView_test.go
This commit is contained in:
Suraj Patil 2016-02-05 23:39:58 +05:30
commit 58918d41af
1 changed files with 51 additions and 0 deletions

View File

@ -33,3 +33,54 @@ func TestUploadedFileHandler(t *testing.T) {
t.Errorf("Actual content (%s) did not match expected content (%s)", actualContent, expectedContent) t.Errorf("Actual content (%s) did not match expected content (%s)", actualContent, expectedContent)
} }
} }
//TestAddEmptyCategory tests that if the category field is empty it should do nothing
func TestAddEmptyCategory(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(AddCategoryFunc))
defer ts.Close()
req, err := http.NewRequest("POST", ts.URL, nil)
req.Form = make(map[string][]string, 0)
req.Form.Add("category", "")
// req.Form, _ = url.ParseQuery("category=")
if err != nil {
t.Errorf("Error occured while constracting request:%s", err)
}
w := httptest.NewRecorder()
AddCategoryFunc(w, req)
body := w.Body.String()
if len(body) != 0 {
t.Error("Body should be empty. Instead contained data: ", body)
}
}
func TestEditTaskWithWrongMethod(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(EditTaskFunc))
defer ts.Close()
req, err := http.NewRequest("OPTIONS", ts.URL, nil)
if err != nil {
t.Errorf("Error occured while constracting request:%s", err)
}
w := httptest.NewRecorder()
EditTaskFunc(w, req)
if w.Code != http.StatusFound && message != "Method not allowed" {
t.Errorf("Message was: %s Return code was: %d. Should have been message: %s return code: %d", message, w.Code, "Method not allowed", http.StatusFound)
}
}
func TestEditTaskWrongTaskName(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(EditTaskFunc))
defer ts.Close()
ts.URL = ts.URL + "/edit/invalidID"
req, err := http.NewRequest("GET", ts.URL, nil)
if err != nil {
t.Errorf("Error occured while constracting request:%s", err)
}
w := httptest.NewRecorder()
EditTaskFunc(w, req)
//TODO: Error should be returned as part of the string so that the message can tell
//why there was a problem.
if w.Code != http.StatusBadRequest {
t.Errorf("Actual status: (%d); Expected status:(%d)", w.Code, http.StatusBadRequest)
}
}