expand store.go coverage to 100% with a tricky test
- force http.Request.ParseForm to fail
This commit is contained in:
parent
f076f3a88a
commit
edc49d9915
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -222,7 +223,28 @@ func TestStoreWithGet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func TestStoreWithUrlEncodedFormParseError(t *testing.T) {
|
||||||
|
// http.Request.ParseForm() fails when:
|
||||||
|
// - http.Request.Method is one of [POST,PUT,PATCH]
|
||||||
|
// - http.Request.Form is not nil (created manually)
|
||||||
|
// - http.Request.PostForm is nil (deleted manually)
|
||||||
|
// - http.Request.Body is nil (deleted manually)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "http://host.com/", nil)
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
// break everything
|
||||||
|
req.Body = nil
|
||||||
|
req.Form = make(url.Values)
|
||||||
|
req.PostForm = nil
|
||||||
|
|
||||||
|
// defer req.Body.Close()
|
||||||
|
store := New(nil, req)
|
||||||
|
if len(store.Form) > 0 {
|
||||||
|
t.Errorf("expected malformed urlencoded to have failed being parsed (got %d elements)", len(store.Form))
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
func TestStoreWithUrlEncodedForm(t *testing.T) {
|
func TestStoreWithUrlEncodedForm(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
URLEncoded string
|
URLEncoded string
|
||||||
|
|
Loading…
Reference in New Issue