From fd803b1fe06c0cdac2ae1c8d83cff93b52a53c6a Mon Sep 17 00:00:00 2001 From: Nurzhan Ilyassov <“nilyassov@one.kz”> Date: Tue, 26 Mar 2024 12:44:45 +0500 Subject: [PATCH] update tests --- util_test.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/util_test.go b/util_test.go index d1fb061..1c0b713 100644 --- a/util_test.go +++ b/util_test.go @@ -61,24 +61,32 @@ func TestNewPathRequest(t *testing.T) { func TestNewPathRequestWithEmptyBody(t *testing.T) { val := struct{}{} + cases := []string{ + "", + "*", + "{}", + "nil", + `{"type": "invalid"}`, + } - 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") - } + for _, body := range cases { + for _, m := range []string{"POST", "PUT", "PATCH", "GET", "DELETE"} { + 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) + 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) + } } } }