micro-client-http/util_test.go
Vasiliy Tolstov 602aed03bd support path params not only for get requests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-19 14:17:53 +03:00

33 lines
639 B
Go

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)
}
}
}