fix nil nmsg in case of empty request body

This commit is contained in:
Nurzhan Ilyassov
2024-03-26 11:09:38 +05:00
committed by Vasiliy Tolstov
parent 7ea55fb466
commit bc59fcb886
2 changed files with 33 additions and 1 deletions

View File

@@ -59,6 +59,30 @@ func TestNewPathRequest(t *testing.T) {
}
}
func TestNewPathRequestWithEmptyBody(t *testing.T) {
val := struct{}{}
for _, m := range []string{"POST", "PUT", "PATCH", "GET", "DELETE"} {
body := `{"type": "invalid"}`
path, nmsg, err := newPathRequest("/v1/test", m, body, val, []string{"protobuf", "json"}, nil)
if err != nil {
t.Fatal(err)
}
if nmsg == nil {
t.Fatalf("invalid path: nil nmsg")
}
u, err := url.Parse(path)
if err != nil {
t.Fatal(err)
}
vals := u.Query()
if len(vals) != 0 {
t.Fatalf("invalid path: %v nmsg: %v", path, nmsg)
}
}
}
func TestNewPathVarRequest(t *testing.T) {
type Message struct {
Name string `json:"name"`