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