forked from electricdusk/rushlink
parent
50baaeadf1
commit
9d952edc67
@ -184,3 +184,38 @@ func TestIssue56(t *testing.T) {
|
|||||||
srv.ServeHTTP(rr, req)
|
srv.ServeHTTP(rr, req)
|
||||||
checkStatusCode(t, rr, http.StatusBadRequest)
|
checkStatusCode(t, rr, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue68(t *testing.T) {
|
||||||
|
srv, _ := createTemporaryRouter(t)
|
||||||
|
originalURL := "https://example.com"
|
||||||
|
|
||||||
|
var body bytes.Buffer
|
||||||
|
form := multipart.NewWriter(&body)
|
||||||
|
form.WriteField("shorten", "https://example.com")
|
||||||
|
form.Close()
|
||||||
|
req, err := http.NewRequest("POST", "/", bytes.NewReader(body.Bytes()))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
req.Header.Add("Content-Type", form.FormDataContentType())
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
srv.ServeHTTP(rr, req)
|
||||||
|
checkStatusCode(t, rr, http.StatusFound)
|
||||||
|
rawURL := strings.SplitN(rr.Body.String(), "\n", 2)[0]
|
||||||
|
pasteURL, err := url.Parse(rawURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the no-redirect handler works properly.
|
||||||
|
req, err = http.NewRequest("GET", pasteURL.Path+"/nr", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rr = httptest.NewRecorder()
|
||||||
|
srv.ServeHTTP(rr, req)
|
||||||
|
checkStatusCode(t, rr, http.StatusOK)
|
||||||
|
if rr.Body.String() != originalURL {
|
||||||
|
t.Errorf("incorrect URL = %v, want %v", rr.Body.String(), originalURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user