Skip to content

Commit

Permalink
working tests manual resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
eshitachandwani committed Dec 27, 2024
1 parent 104cd18 commit fb23cca
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/transport/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"testing"
"time"

"golang.org/x/net/http/httpproxy"
"google.golang.org/grpc/internal/proxyattributes"
"google.golang.org/grpc/internal/resolver/delegatingresolver"
"google.golang.org/grpc/resolver"
Expand Down Expand Up @@ -58,16 +59,14 @@ func (s) TestHTTPConnectWithServerHello(t *testing.T) {
}()

// Overwrite the function in the test and restore them in defer.
hpfe := func(req *http.Request) (*url.URL, error) {
return &url.URL{
Scheme: "https",
Host: pLis.Addr().String(),
}, nil
t.Setenv("HTTPS_PROXY", pLis.Addr().String())

origHTTPSProxyFromEnvironment := delegatingresolver.HTTPSProxyFromEnvironment
delegatingresolver.HTTPSProxyFromEnvironment = func(req *http.Request) (*url.URL, error) {
return httpproxy.FromEnvironment().ProxyFunc()(req.URL)
}
orighpfe := delegatingresolver.HTTPSProxyFromEnvironment
delegatingresolver.HTTPSProxyFromEnvironment = hpfe
defer func() {
delegatingresolver.HTTPSProxyFromEnvironment = orighpfe
delegatingresolver.HTTPSProxyFromEnvironment = origHTTPSProxyFromEnvironment
}()

// Dial to proxy server.
Expand Down

0 comments on commit fb23cca

Please sign in to comment.