From 36008db9e570f0c925448ab698133d82c2141233 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 19 Nov 2019 16:15:26 +0100 Subject: [PATCH] Test empty store -> fix --- internal/reqdata/store.go | 5 +++++ internal/reqdata/store_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 internal/reqdata/store_test.go diff --git a/internal/reqdata/store.go b/internal/reqdata/store.go index 514d4d4..0a4d81e 100644 --- a/internal/reqdata/store.go +++ b/internal/reqdata/store.go @@ -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) diff --git a/internal/reqdata/store_test.go b/internal/reqdata/store_test.go new file mode 100644 index 0000000..c973268 --- /dev/null +++ b/internal/reqdata/store_test.go @@ -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() + } +}