Skip to content

Commit

Permalink
working post method allows us to create short links
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Nunogawa committed Oct 14, 2014
1 parent 69c3859 commit a586631
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gtls/handler_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (handler *AdminHandler) Respond(req *http.Request) (statusCode int, headers
switch url_path {
case "/admin/post":
if req.Method == "POST" {
// temporary just respond okay
handler.linksDB[req.FormValue("code")] = req.FormValue("url")
return http.StatusOK, nil, []byte("ok")
} else {
return http.StatusMethodNotAllowed, nil, []byte("Method not allowed")
Expand Down
22 changes: 19 additions & 3 deletions gtls/handler_admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,32 @@ func TestGetAPostRoute(t *testing.T) {
}

func TestCreateShortlink(t *testing.T) {
post_url := test_server.URL + "/admin/post"
short_code := "TestCreateShortlink"

// first test to make sure our short code returns 404
short_url := test_server.URL + "/" + short_code
res, err := http.Get(short_url)
if err != nil {
log.Fatal(1819562567, short_url, err)
}
assertEqual(t, 404, res.StatusCode, short_url)

// post our form
post_url := test_server.URL + "/admin/post"
client := http.Client{}
form_vals := url.Values{}
form_vals.Add("url", "http://twitter.com/GoTutorialNet")
res, err := client.PostForm(post_url, form_vals)
form_vals.Add("code", short_code)
res, err = client.PostForm(post_url, form_vals)
if err != nil {
log.Fatal(1819562566, post_url, err)
}

assertEqual(t, 200, res.StatusCode, post_url)

// check to make sure our short code works after posting
res, err = http.Get(short_url)
if err != nil {
log.Fatal(1819562567, post_url, err)
}
assertEqual(t, 200, res.StatusCode, post_url)
}
2 changes: 1 addition & 1 deletion gtls/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

const (
internal_BUILD_NUMBER = 8
internal_BUILD_NUMBER = 9
internal_VERSION_STRING = "0.0.1"
)

Expand Down

0 comments on commit a586631

Please sign in to comment.