MCPcopy
hub / github.com/autobrr/qui / TestHandlerRewriteRequest_PathJoining

Function TestHandlerRewriteRequest_PathJoining

internal/proxy/handler_test.go:30–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestHandlerRewriteRequest_PathJoining(t *testing.T) {
31 t.Helper()
32
33 const (
34 apiKey = "abc123"
35 instanceID = 7
36 clientName = "autobrr"
37 )
38
39 baseCases := []struct {
40 name string
41 baseURL string
42 requestPath string
43 }{
44 {
45 name: "root base",
46 baseURL: "/",
47 requestPath: "/proxy/" + apiKey + "/api/v2/app/webapiVersion",
48 },
49 {
50 name: "custom base",
51 baseURL: "/qui/",
52 requestPath: "/qui/proxy/" + apiKey + "/api/v2/app/webapiVersion",
53 },
54 }
55
56 instanceCases := []struct {
57 name string
58 instanceHost string
59 expectedPath string
60 }{
61 {
62 name: "with sub-path",
63 instanceHost: "https://example.com/qbittorrent",
64 expectedPath: "/qbittorrent/api/v2/app/webapiVersion",
65 },
66 {
67 name: "with sub-path and port",
68 instanceHost: "http://192.0.2.10:8080/qbittorrent",
69 expectedPath: "/qbittorrent/api/v2/app/webapiVersion",
70 },
71 {
72 name: "root host",
73 instanceHost: "https://example.com",
74 expectedPath: "/api/v2/app/webapiVersion",
75 },
76 }
77
78 for _, baseCase := range baseCases {
79 t.Run(baseCase.name, func(t *testing.T) {
80 h := NewHandler(nil, nil, nil, nil, nil, nil, baseCase.baseURL)
81 require.NotNil(t, h)
82
83 for _, tc := range instanceCases {
84 t.Run(tc.name, func(t *testing.T) {
85 req := httptest.NewRequest("GET", baseCase.requestPath, nil)
86
87 routeCtx := chi.NewRouteContext()

Callers

nothing calls this directly

Calls 6

rewriteRequestMethod · 0.95
RunMethod · 0.80
AddMethod · 0.80
CloneMethod · 0.80
NewHandlerFunction · 0.70
ParseMethod · 0.45

Tested by

no test coverage detected