Files
telemt-api/internal/proxy/reverse_test.go
T
Denozordec 91f289c647
ci / test (push) Successful in 1m15s
ci / docker (push) Successful in 1m8s
Init
2026-03-29 22:51:02 +07:00

27 lines
633 B
Go

package proxy
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestReverseProxyPathRewrite(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/health" {
t.Fatalf("path %q", r.URL.Path)
}
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
up, _ := url.Parse(srv.URL)
rp := NewReverseProxy(up, "/api/main_srv", "/v1", "")
req := httptest.NewRequest(http.MethodGet, "/api/main_srv/health", nil)
rec := httptest.NewRecorder()
rp.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status %d", rec.Code)
}
}