-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathhttp2_test.go
executable file
·36 lines (31 loc) · 1.2 KB
/
http2_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//go:build httpvar
// +build httpvar
package chef
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"os"
"reflect"
"testing"
)
// TestNewClientProxy2
// Verify that getting proxy information from environment variables works
// This test needs to be run seperately from other tests
// http.ProxyFromEnvironment will only get the proxy value once, the first time it is called
func TestNewClientProxy2(t *testing.T) {
//test proxy from environment variable
os.Setenv("https_proxy", "https://8.8.8.8:8000")
cfg := &Config{Name: "testclient", Key: privateKeyPKCS1, SkipSSL: false, Timeout: 1}
chefClient, err := NewClient(cfg)
assert.Nil(t, err, "Create client")
request, err := chefClient.NewRequest("GET", "https://test.com", nil)
assert.Nil(t, err, "Create request")
eurl := &url.URL{Scheme: "https", Host: "8.8.8.8:8000"}
trurl, err := chefClient.Client.Transport.(*http.Transport).Proxy(request)
assert.Equal(t, *eurl, *trurl, "proxy value from environment variable")
tr := chefClient.Client.Transport.(*http.Transport)
assert.Equal(t, reflect.ValueOf(tr.Proxy).Pointer(),
reflect.ValueOf(http.ProxyFromEnvironment).Pointer(),
"Proxy set from http proxyfromenvironment function")
}