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 {"localhost", false}, // match completely
20 {"barbaz.net", false}, // match as .barbaz.net
21 {"foobar.com:443", false}, // have a port but match
22 {"foofoobar.com", true}, // not match as a part of foobar.com
23 {"baz.com", true}, // not match as a part of barbaz.com
24 {"localhost.net", true}, // not match as suffix of address
25 {"local.localhost", true}, // not match as prefix as address
26 {"barbarbaz.net", true}, // not match because NO_PROXY have a '.'
27 {"www.foobar.com", true}, // not match because NO_PROXY is not .foobar.com
30 func TestUseProxy(t *testing.T) {
31 oldenv := os.Getenv("NO_PROXY")
32 no_proxy := "foobar.com, .barbaz.net , localhost"
33 os.Setenv("NO_PROXY", no_proxy)
34 defer os.Setenv("NO_PROXY", oldenv)
38 for _, test := range UseProxyTests {
39 if tr.useProxy(test.host) != test.match {
41 t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
43 t.Errorf("not expected: '%s' shouldn't match as '%s'", test.host, no_proxy)