MCPcopy
hub / github.com/gofiber/fiber / Test_Parser_Request_URL

Function Test_Parser_Request_URL

client/hooks_test.go:59–244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func Test_Parser_Request_URL(t *testing.T) {
60 t.Parallel()
61
62 t.Run("client baseurl should be set", func(t *testing.T) {
63 t.Parallel()
64 client := New().SetBaseURL("http://example.com/api")
65 req := AcquireRequest().SetURL("")
66
67 err := parserRequestURL(client, req)
68 require.NoError(t, err)
69 require.Equal(t, "http://example.com/api", req.RawRequest.URI().String())
70 })
71
72 t.Run("request url should be set", func(t *testing.T) {
73 t.Parallel()
74 client := New()
75 req := AcquireRequest().SetURL("http://example.com/api")
76
77 err := parserRequestURL(client, req)
78 require.NoError(t, err)
79 require.Equal(t, "http://example.com/api", req.RawRequest.URI().String())
80 })
81
82 t.Run("the request url will override baseurl with protocol", func(t *testing.T) {
83 t.Parallel()
84 client := New().SetBaseURL("http://example.com/api")
85 req := AcquireRequest().SetURL("http://example.com/api/v1")
86
87 err := parserRequestURL(client, req)
88 require.NoError(t, err)
89 require.Equal(t, "http://example.com/api/v1", req.RawRequest.URI().String())
90 })
91
92 t.Run("the request url should be append after baseurl without protocol", func(t *testing.T) {
93 t.Parallel()
94 client := New().SetBaseURL("http://example.com/api")
95 req := AcquireRequest().SetURL("/v1")
96
97 err := parserRequestURL(client, req)
98 require.NoError(t, err)
99 require.Equal(t, "http://example.com/api/v1", req.RawRequest.URI().String())
100 })
101
102 t.Run("the url is error", func(t *testing.T) {
103 t.Parallel()
104 client := New().SetBaseURL("example.com/api")
105 req := AcquireRequest().SetURL("/v1")
106
107 err := parserRequestURL(client, req)
108 require.Equal(t, ErrURLFormat, err)
109 })
110
111 t.Run("the path param from client", func(t *testing.T) {
112 t.Parallel()
113 client := New().
114 SetBaseURL("http://example.com/api/:id").
115 SetPathParam("id", "5")
116 req := AcquireRequest()

Callers

nothing calls this directly

Calls 14

AcquireRequestFunction · 0.85
parserRequestURLFunction · 0.85
ReleaseRequestFunction · 0.85
SetBaseURLMethod · 0.80
SetURLMethod · 0.80
URIMethod · 0.80
NewFunction · 0.70
StringMethod · 0.65
FatalfMethod · 0.65
SetPathParamMethod · 0.45
DelPathParamsMethod · 0.45
SetPathParamsMethod · 0.45

Tested by

no test coverage detected