@@ -22,7 +22,6 @@ import (
2222 "flag"
2323 "fmt"
2424 "io"
25- "net/http"
2625 "net/http/httptest"
2726 "os"
2827 "path/filepath"
@@ -460,10 +459,9 @@ func TestPprofRouting(t *testing.T) {
460459 telemetryMux := buildTelemetryServer (reg , false , nil )
461460 for _ , path := range pprofPaths {
462461 req := httptest .NewRequest ("GET" , "http://localhost:8081" + path , nil )
463- w := httptest .NewRecorder ()
464- telemetryMux .ServeHTTP (w , req )
465- if w .Result ().StatusCode == http .StatusNotFound {
466- t .Errorf ("expected pprof path %s to be registered on telemetry server, got 404" , path )
462+ _ , pattern := telemetryMux .Handler (req )
463+ if pattern == "" {
464+ t .Errorf ("expected pprof path %s to be registered on telemetry server, got no match" , path )
467465 }
468466 }
469467
@@ -475,12 +473,15 @@ func TestPprofRouting(t *testing.T) {
475473 false ,
476474 nil ,
477475 )
476+ pprofPatterns := make (map [string ]struct {}, len (pprofPaths ))
477+ for _ , path := range pprofPaths {
478+ pprofPatterns [path ] = struct {}{}
479+ }
478480 for _ , path := range pprofPaths {
479481 req := httptest .NewRequest ("GET" , "http://localhost:8080" + path , nil )
480- w := httptest .NewRecorder ()
481- metricsMux .ServeHTTP (w , req )
482- if w .Result ().StatusCode != http .StatusNotFound {
483- t .Errorf ("expected pprof path %s to return 404 on metrics server, got %d" , path , w .Result ().StatusCode )
482+ _ , pattern := metricsMux .Handler (req )
483+ if _ , ok := pprofPatterns [pattern ]; ok {
484+ t .Errorf ("expected pprof path %s to be unregistered on metrics server, matched pattern %q" , path , pattern )
484485 }
485486 }
486487}
0 commit comments