util/http: add test case

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-10-02 18:34:22 +03:00
parent 8abc913b28
commit ada59119cc

View File

@ -5,6 +5,22 @@ import (
"testing"
)
func TestTrieFixedPattern(t *testing.T) {
type handler struct {
name string
}
tr := NewTrie()
tr.Insert([]string{http.MethodPut}, "/v1/create/{id}", &handler{name: "pattern"})
tr.Insert([]string{http.MethodPut}, "/v1/create/12", &handler{name: "fixed"})
h, _, ok := tr.Search(http.MethodPut, "/v1/create/12", IgnoreCase(false))
if !ok {
t.Fatalf("unexpected error")
}
if h.(*handler).name != "fixed" {
t.Fatalf("invalid handler %v", h)
}
}
func TestTrieIgnoreCase(t *testing.T) {
type handler struct {
name string