LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package http | 5 package http |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "testing" | 9 "testing" |
10 ) | 10 ) |
11 | 11 |
12 // TODO(mattn): | 12 // TODO(mattn): |
13 // test ProxyAuth | 13 // test ProxyAuth |
14 | 14 |
15 var MatchNoProxyTests = []struct { | 15 var UseProxyTests = []struct { |
16 host string | 16 host string |
17 match bool | 17 match bool |
18 }{ | 18 }{ |
19 » {"localhost", true}, // match completely | 19 » {"localhost", false}, // match completely |
20 » {"barbaz.net", true}, // match as .barbaz.net | 20 » {"barbaz.net", false}, // match as .barbaz.net |
21 » {"foobar.com:443", true}, // have a port but match· | 21 » {"foobar.com:443", false}, // have a port but match· |
22 » {"foofoobar.com", false}, // not match as a part of foobar.com | 22 » {"foofoobar.com", true}, // not match as a part of foobar.com |
23 » {"baz.com", false}, // not match as a part of barbaz.com | 23 » {"baz.com", true}, // not match as a part of barbaz.com |
24 » {"localhost.net", false}, // not match as suffix of address | 24 » {"localhost.net", true}, // not match as suffix of address |
25 » {"local.localhost", false}, // not match as prefix as address | 25 » {"local.localhost", true}, // not match as prefix as address |
26 » {"barbarbaz.net", false}, // not match because NO_PROXY have a '.' | 26 » {"barbarbaz.net", true}, // not match because NO_PROXY have a '.' |
27 » {"www.foobar.com", false}, // not match because NO_PROXY is not .foobar
.com | 27 » {"www.foobar.com", true}, // not match because NO_PROXY is not .foobar.
com |
28 } | 28 } |
29 | 29 |
30 func TestMatchNoProxy(t *testing.T) { | 30 func TestUseProxy(t *testing.T) { |
31 oldenv := os.Getenv("NO_PROXY") | 31 oldenv := os.Getenv("NO_PROXY") |
32 no_proxy := "foobar.com, .barbaz.net , localhost" | 32 no_proxy := "foobar.com, .barbaz.net , localhost" |
33 os.Setenv("NO_PROXY", no_proxy) | 33 os.Setenv("NO_PROXY", no_proxy) |
34 defer os.Setenv("NO_PROXY", oldenv) | 34 defer os.Setenv("NO_PROXY", oldenv) |
35 | 35 |
36 tr := &Transport{} | 36 tr := &Transport{} |
37 | 37 |
38 » for _, test := range MatchNoProxyTests { | 38 » for _, test := range UseProxyTests { |
39 » » if tr.matchNoProxy(test.host) != test.match { | 39 » » if tr.useProxy(test.host) != test.match { |
40 if test.match { | 40 if test.match { |
41 » » » » t.Errorf("matchNoProxy(%v) = %v, want %v", test.
host, !test.match, test.match) | 41 » » » » t.Errorf("useProxy(%v) = %v, want %v", test.host
, !test.match, test.match) |
42 } else { | 42 } else { |
43 t.Errorf("not expected: '%s' shouldn't match as
'%s'", test.host, no_proxy) | 43 t.Errorf("not expected: '%s' shouldn't match as
'%s'", test.host, no_proxy) |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 } | 47 } |
LEFT | RIGHT |