grafana/pkg/services/ngalert/state/historian/client_test.go
Alexander Weaver a8fb01a502
Swap weaveworks/common utilities for equivalents in grafana/dskit (#80051)
* Replace histogram collector and grpc injectors

* Extract request timing utility

* Also vendor test file

* Suppress erroneous linter warn
2024-01-05 10:08:38 -06:00

30 lines
727 B
Go

package historian
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTimedClient_operationName(t *testing.T) {
r, err := http.NewRequest("GET", "https://weave.test", nil)
assert.NoError(t, err)
r = r.WithContext(context.WithValue(context.Background(), OperationNameContextKey, "opp"))
c := NewTimedClient(http.DefaultClient, nil)
assert.Equal(t, "opp", c.operationName(r))
}
func TestTimedClient_operationName_Default(t *testing.T) {
r, err := http.NewRequest("GET", "https://weave.test/you/know/me", nil)
assert.NoError(t, err)
r = r.WithContext(context.Background())
c := NewTimedClient(http.DefaultClient, nil)
assert.Equal(t, "/you/know/me", c.operationName(r))
}