github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/http/client/client_test.go (about) 1 package client 2 3 import ( 4 "context" 5 "net/http" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestTimedClient_operationName(t *testing.T) { 12 r, err := http.NewRequest("GET", "https://weave.test", nil) 13 assert.NoError(t, err) 14 15 r = r.WithContext(context.WithValue(context.Background(), OperationNameContextKey, "opp")) 16 c := NewTimedClient(http.DefaultClient, nil) 17 18 assert.Equal(t, "opp", c.operationName(r)) 19 } 20 21 func TestTimedClient_operationName_Default(t *testing.T) { 22 r, err := http.NewRequest("GET", "https://weave.test/you/know/me", nil) 23 assert.NoError(t, err) 24 25 r = r.WithContext(context.Background()) 26 c := NewTimedClient(http.DefaultClient, nil) 27 28 assert.Equal(t, "/you/know/me", c.operationName(r)) 29 }