Skip to content

Commit

Permalink
Use full roundtripper
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
  • Loading branch information
roidelapluie committed Jun 30, 2022
1 parent 316097c commit 2d0de85
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions config/http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,10 +1234,8 @@ endpoint_params:

func TestOAuth2UserAgent(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
if r.Header.Get("User-Agent") != "myuseragent" {
t.Fatalf("Expected User-Agent header in oauth request to be 'myuseragent', got '%s'", r.Header.Get("User-Agent"))
}
if r.Header.Get("User-Agent") != "myuseragent" {
t.Fatalf("Expected User-Agent header in oauth request to be 'myuseragent', got '%s'", r.Header.Get("User-Agent"))
}

res, _ := json.Marshal(oauth2TestServerResponse{
Expand All @@ -1249,18 +1247,19 @@ func TestOAuth2UserAgent(t *testing.T) {
}))
defer ts.Close()

config := &OAuth2{
config := DefaultHTTPClientConfig
config.OAuth2 = &OAuth2{
ClientID: "1",
ClientSecret: "2",
Scopes: []string{"A", "B"},
EndpointParams: map[string]string{"hi": "hello"},
TokenURL: fmt.Sprintf("%s/token", ts.URL),
}

opts := defaultHTTPClientOptions
WithUserAgent("myuseragent")(&opts)

rt := NewOAuth2RoundTripper(config, http.DefaultTransport, &opts)
rt, err := NewRoundTripperFromConfig(config, "test_oauth2", WithUserAgent("myuseragent"))
if err != nil {
t.Fatal(err)
}

client := http.Client{
Transport: rt,
Expand Down

0 comments on commit 2d0de85

Please sign in to comment.