Test empty store -> fix

This commit is contained in:
Adrien Marquès 2019-11-19 16:15:26 +01:00
parent 8a1144a187
commit 36008db9e5
2 changed files with 39 additions and 0 deletions

View File

@ -57,6 +57,11 @@ func New(uriParams []string, req *http.Request) *Store {
// 1. set URI parameters
ds.setURIParams(uriParams)
// ignore nil requests
if req == nil {
return ds
}
// 2. GET (query) data
ds.readQuery(req)

View File

@ -0,0 +1,34 @@
package reqdata
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestEmptyStore(t *testing.T) {
store := New(nil, nil)
if store.URI == nil {
t.Errorf("store 'URI' list should be initialized")
t.Fail()
}
if len(store.URI) != 0 {
t.Errorf("store 'URI' list should be empty")
t.Fail()
}
if store.Get == nil {
t.Errorf("store 'Get' map should be initialized")
t.Fail()
}
if store.Form == nil {
t.Errorf("store 'Form' map should be initialized")
t.Fail()
}
if store.Set == nil {
t.Errorf("store 'Set' map should be initialized")
t.Fail()
}
}