1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 var UseProxyTests = []struct {
20 // Never proxy localhost:
21 {"localhost:80", false},
25 {"[::2]", true}, // not a loopback address
27 {"barbaz.net", false}, // match as .barbaz.net
28 {"foobar.com", false}, // have a port but match
29 {"foofoobar.com", true}, // not match as a part of foobar.com
30 {"baz.com", true}, // not match as a part of barbaz.com
31 {"localhost.net", true}, // not match as suffix of address
32 {"local.localhost", true}, // not match as prefix as address
33 {"barbarbaz.net", true}, // not match because NO_PROXY have a '.'
34 {"www.foobar.com", false}, // match because NO_PROXY includes "foobar.com"
37 func TestUseProxy(t *testing.T) {
38 oldenv := os.Getenv("NO_PROXY")
39 defer os.Setenv("NO_PROXY", oldenv)
41 no_proxy := "foobar.com, .barbaz.net"
42 os.Setenv("NO_PROXY", no_proxy)
44 for _, test := range UseProxyTests {
45 if useProxy(test.host+":80") != test.match {
46 t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
51 var cacheKeysTests = []struct {
57 {"", "http", "foo.com", "|http|foo.com"},
58 {"", "https", "foo.com", "|https|foo.com"},
59 {"http://foo.com", "http", "foo.com", "http://foo.com|http|"},
60 {"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"},
63 func TestCacheKeys(t *testing.T) {
64 for _, tt := range cacheKeysTests {
67 u, err := url.Parse(tt.proxy)
73 cm := connectMethod{proxy, tt.scheme, tt.addr}
74 if cm.String() != tt.key {
75 t.Fatalf("{%q, %q, %q} cache key %q; want %q", tt.proxy, tt.scheme, tt.addr, cm.String(), tt.key)