support path params not only for get requests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-03-19 14:17:53 +03:00
parent 1919ef3830
commit 602aed03bd
4 changed files with 49 additions and 161 deletions

32
util_test.go Normal file
View File

@@ -0,0 +1,32 @@
package http
import (
"net/url"
"testing"
)
func TestNewPathRequest(t *testing.T) {
type Message struct {
Name string
Val1 string
Val2 int64
Val3 []string
}
omsg := &Message{Name: "test_name", Val1: "test_val1", Val2: 100, Val3: []string{"slice"}}
for _, m := range []string{"POST", "PUT", "PATCH", "GET", "DELETE"} {
path, nmsg, err := newPathRequest("/v1/test", m, "", omsg)
if err != nil {
t.Fatal(err)
}
u, err := url.Parse(path)
if err != nil {
t.Fatal(err)
}
vals := u.Query()
if v, ok := vals["name"]; !ok || v[0] != "test_name" {
t.Fatalf("invlid path: %v nmsg: %v", path, nmsg)
}
}
}