Skip to content

Commit

Permalink
Merge pull request #26 from ory-am/Thusday
Browse files Browse the repository at this point in the history
test the REST HEAD verb
  • Loading branch information
Aeneas committed Apr 19, 2016
2 parents 9f20aff + 9fb5005 commit a149f0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,17 @@ func ListContacts(store ContactStorer) func(rw http.ResponseWriter, r *http.Requ
}

pkg.WriteIndentJSON(rw, contacts)

}
}

// ContactsMeta gets the metadata.
func ContactsMeta (rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type","application/json")


}

// AddContact will add a contact to the list
func AddContact(contacts ContactStorer) func(rw http.ResponseWriter, r *http.Request) {
return func(rw http.ResponseWriter, r *http.Request) {
Expand Down
19 changes: 19 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ func TestListContacts(t *testing.T) {
// This helper function makes an http request to ListContacts and validates its output.
fetchAndTestContactList(t, ts, mockedContactList)
}
func TestHeadContacts(t *testing.T) {


// Initialize everything (very similar to main() function).
router := mux.NewRouter()
router.HandleFunc("/contacts", ContactsMeta).Methods("HEAD")
ts := httptest.NewServer(router)

// This helper function makes an http request to ListContacts and validates its output.
fetchAndTestContactHead(t, ts)
}
func TestAddContacts(t *testing.T) {
// We create a copy of the store
contactListForThisTest := copyContacts(mockedContactList)
Expand Down Expand Up @@ -179,7 +189,16 @@ func fetchAndTestContactList(t *testing.T, ts *httptest.Server, compareWith Cont
// Compare the outputs
assert.Equal(t, compareWith, result)
}
func fetchAndTestContactHead(t *testing.T, ts *httptest.Server) {
// Request ListContacts
resp, err := http.Head(ts.URL + "/contacts")

// Verify that no errors occurred
require.Nil(t, err)
// Compare the outputs
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
t.Logf("%s", resp.Header)
}
func copyContacts(original Contacts) Contacts {
result := Contacts{}
for k, v := range original {
Expand Down

0 comments on commit a149f0c

Please sign in to comment.