support path params not only for get requests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
32
util_test.go
Normal file
32
util_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user