OSDN Git Service

Update to current version of Go library.
[pf3gnuchains/gcc-fork.git] / libgo / go / http / proxy_test.go
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.
4
5 package http
6
7 import (
8         "os"
9         "testing"
10 )
11
12 // TODO(mattn):
13 //      test ProxyAuth
14
15 var UseProxyTests = []struct {
16         host  string
17         match bool
18 }{
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
28 }
29
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)
35
36         tr := &Transport{}
37
38         for _, test := range UseProxyTests {
39                 if tr.useProxy(test.host) != test.match {
40                         if test.match {
41                                 t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
42                         } else {
43                                 t.Errorf("not expected: '%s' shouldn't match as '%s'", test.host, no_proxy)
44                         }
45                 }
46         }
47 }