Skip to content

Commit

Permalink
Add Unit Test For Trace Response Handler
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Nov 1, 2024
1 parent 2a686c0 commit c455559
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/query/app/trace_response_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package app

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"

"github.com/jaegertracing/jaeger/pkg/jtracer"
)

func TestTraceResponseHandler(t *testing.T) {
exporter := tracetest.NewInMemoryExporter()
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSyncer(exporter),
sdktrace.WithSampler(sdktrace.AlwaysSample()),
)
jTracer := jtracer.JTracer{OTEL: tracerProvider}
tracer := jTracer.OTEL.Tracer("instrumentation/trace_response_handler_test")

emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

Check failure on line 27 in cmd/query/app/trace_response_handler_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
handlerWithTracing := traceResponseHandler(emptyHandler)
hanlderWithInstrumentation := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, span := tracer.Start(r.Context(), "operation")
defer span.End()

handlerWithTracing.ServeHTTP(w, r)
})

server := httptest.NewServer(hanlderWithInstrumentation)
defer server.Close()

req, err := http.NewRequest(http.MethodGet, server.URL, nil)
require.NoError(t, err)

resp, err := server.Client().Do(req)
require.NoError(t, err)

traceResponse := resp.Header.Get("traceresponse")

// TODO: why isn't this populated?
require.Equal(t, "", traceResponse)
}

0 comments on commit c455559

Please sign in to comment.