Test empty store -> fix

This commit is contained in:
Adrien Marquès 2019-11-19 16:15:26 +01:00
parent c40fb03aa7
commit 613233faef
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
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 // 1. set URI parameters
ds.setURIParams(uriParams) ds.setURIParams(uriParams)
// ignore nil requests
if req == nil {
return ds
}
// 2. GET (query) data // 2. GET (query) data
ds.readQuery(req) 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()
}
}