MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestHTTPClient_PathHandling

Function TestHTTPClient_PathHandling

pkg/api/http_test.go:246–274  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

244}
245
246func TestHTTPClient_PathHandling(t *testing.T) {
247 tests := []struct {
248 name string
249 inputPath string
250 expectedPath string
251 }{
252 {"path with leading slash", "/api/test", "/api/test"},
253 {"path without leading slash", "api/test", "/api/test"},
254 {"root path", "/", "/"},
255 {"empty path", "", "/"},
256 }
257
258 for _, tt := range tests {
259 t.Run(tt.name, func(t *testing.T) {
260 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
261 assert.Equal(t, tt.expectedPath, r.URL.Path)
262 w.WriteHeader(http.StatusOK)
263 _ = json.NewEncoder(w).Encode(map[string]interface{}{"success": true})
264 }))
265 defer server.Close()
266
267 client := NewHTTPClient(server.Client(), server.URL, testutils.NewTestLogger())
268
269 var result map[string]interface{}
270 err := client.Get(context.Background(), tt.inputPath, &result)
271 require.NoError(t, err)
272 })
273 }
274}
275
276func TestHTTPClient_HTTPErrors(t *testing.T) {
277 tests := []struct {

Callers

nothing calls this directly

Calls 6

GetMethod · 0.95
NewTestLoggerFunction · 0.92
NewHTTPClientFunction · 0.85
RunMethod · 0.80
ClientMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected