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.
15 var UseProxyTests = []struct {
19 // Never proxy localhost:
20 {"localhost:80", false},
24 {"[::2]", true}, // not a loopback address
26 {"barbaz.net", false}, // match as .barbaz.net
27 {"foobar.com", false}, // have a port but match
28 {"foofoobar.com", true}, // not match as a part of foobar.com
29 {"baz.com", true}, // not match as a part of barbaz.com
30 {"localhost.net", true}, // not match as suffix of address
31 {"local.localhost", true}, // not match as prefix as address
32 {"barbarbaz.net", true}, // not match because NO_PROXY have a '.'
33 {"www.foobar.com", true}, // not match because NO_PROXY is not .foobar.com
36 func TestUseProxy(t *testing.T) {
37 oldenv := os.Getenv("NO_PROXY")
38 defer os.Setenv("NO_PROXY", oldenv)
40 no_proxy := "foobar.com, .barbaz.net"
41 os.Setenv("NO_PROXY", no_proxy)
43 for _, test := range UseProxyTests {
44 if useProxy(test.host+":80") != test.match {
45 t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)