2021-01-19 04:12:31 +03:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2021-02-06 19:05:55 +03:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
2021-01-19 04:12:31 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Request struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Field1 string
|
|
|
|
Field2 string
|
|
|
|
Field3 int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidPath(t *testing.T) {
|
|
|
|
req := &Request{Name: "vtolstov", Field1: "field1", Field2: "field2", Field3: 10}
|
2021-03-23 00:29:27 +03:00
|
|
|
p, m, err := newPathRequest("/api/v1/{name}/list", "GET", "", req, nil)
|
2021-01-19 04:12:31 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-02-06 19:05:55 +03:00
|
|
|
u, err := url.Parse(p)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
_ = m
|
|
|
|
parts := strings.Split(u.RawQuery, "&")
|
|
|
|
if len(parts) != 3 {
|
|
|
|
t.Fatalf("invalid path: %v", parts)
|
|
|
|
}
|
2021-01-19 04:12:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidPath(t *testing.T) {
|
|
|
|
req := &Request{Name: "vtolstov", Field1: "field1", Field2: "field2", Field3: 10}
|
2021-03-23 00:29:27 +03:00
|
|
|
p, m, err := newPathRequest("/api/v1/{xname}/list", "GET", "", req, nil)
|
2021-01-19 04:12:31 +03:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("path param must not be filled")
|
|
|
|
}
|
|
|
|
_, _ = p, m
|
|
|
|
}
|