MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / TestNewOSSClientUsesEnvironmentHTTPSProxy

Function TestNewOSSClientUsesEnvironmentHTTPSProxy

internal/net/oss_test.go:11–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestNewOSSClientUsesEnvironmentHTTPSProxy(t *testing.T) {
12 oldConf := conf.Conf
13 conf.Conf = conf.DefaultConfig("data")
14 defer func() {
15 conf.Conf = oldConf
16 }()
17
18 t.Setenv("HTTP_PROXY", "")
19 t.Setenv("http_proxy", "")
20 t.Setenv("HTTPS_PROXY", "http://127.0.0.1:7890")
21 t.Setenv("https_proxy", "")
22 t.Setenv("NO_PROXY", "")
23 t.Setenv("no_proxy", "")
24
25 client, err := NewOSSClient("https://oss-cn-hangzhou.aliyuncs.com", "test-access-key", "test-access-secret")
26 if err != nil {
27 t.Fatalf("expected no error, got %v", err)
28 }
29
30 if client.HTTPClient == nil {
31 t.Fatal("expected OSS client to use a custom HTTP client")
32 }
33
34 transport, ok := client.HTTPClient.Transport.(*http.Transport)
35 if !ok {
36 t.Fatalf("expected *http.Transport, got %T", client.HTTPClient.Transport)
37 }
38
39 if transport.Proxy == nil {
40 t.Fatal("expected proxy function to be configured")
41 }
42
43 req := &http.Request{URL: &url.URL{Scheme: "https", Host: "oss-cn-hangzhou.aliyuncs.com"}}
44 proxyURL, err := transport.Proxy(req)
45 if err != nil {
46 t.Fatalf("expected no proxy lookup error, got %v", err)
47 }
48 if proxyURL == nil {
49 t.Fatal("expected HTTPS proxy to be used")
50 }
51 if got, want := proxyURL.String(), "http://127.0.0.1:7890"; got != want {
52 t.Fatalf("expected proxy %q, got %q", want, got)
53 }
54}

Callers

nothing calls this directly

Calls 3

DefaultConfigFunction · 0.92
NewOSSClientFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected