Browse Source

Fixed broken unit test

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
1e6728f460
  1. 5
      handlers/handlers.go
  2. 10
      handlers/handlers_test.go

5
handlers/handlers.go

@ -195,7 +195,10 @@ func (h *Handler) handleInfo(c *gin.Context) {
// handleAccess handles the access for incoming requests
func (h *Handler) handleAccess(c *gin.Context) {
id := c.Param("id")
var id string
if len(c.Request.URL.Path) > 1 {
id = c.Request.URL.Path[1:]
}
entry, err := h.store.GetEntryByID(id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})

10
handlers/handlers_test.go

@ -3,7 +3,6 @@ package handlers
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
@ -92,7 +91,6 @@ func TestCreateEntry(t *testing.T) {
if err != nil {
t.Fatalf("could not unmarshal data: %v", err)
}
fmt.Println(parsed.URL)
t.Run("test if shorted URL is correct", func(t *testing.T) {
testRedirect(t, parsed.URL, tc.requestBody.URL)
})
@ -225,16 +223,16 @@ func testRedirect(t *testing.T, shortURL, longURL string) {
if err != nil {
t.Fatalf("could not parse shorted URL: %v", err)
}
respShort, err := client.Do(&http.Request{
resp, err := client.Do(&http.Request{
URL: u,
})
if err != nil {
t.Fatalf("could not do http request to shorted URL: %v", err)
}
if respShort.StatusCode != http.StatusTemporaryRedirect {
t.Fatalf("expected status code: %d; got: %d", http.StatusTemporaryRedirect, respShort.StatusCode)
if resp.StatusCode != http.StatusTemporaryRedirect {
t.Fatalf("expected status code: %d; got: %d", http.StatusTemporaryRedirect, resp.StatusCode)
}
if respShort.Header.Get("Location") != longURL {
if resp.Header.Get("Location") != longURL {
t.Fatalf("redirect URL is not correct")
}
}

Loading…
Cancel
Save