~rogpeppe/juju-core/themue-058-debug-log-api

« back to all changes in this revision

Viewing changes to juju/osenv/proxy_test.go

  • Committer: Frank Mueller
  • Date: 2014-01-21 08:46:24 UTC
  • mfrom: (2152.1.76 juju-core)
  • Revision ID: frank.mueller@canonical.com-20140121084624-rv32dv6ufzul9h1b
debugger: merged trunk and added access to debugger API facade

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package osenv_test
 
5
 
 
6
import (
 
7
        gc "launchpad.net/gocheck"
 
8
 
 
9
        "launchpad.net/juju-core/juju/osenv"
 
10
        "launchpad.net/juju-core/testing/testbase"
 
11
)
 
12
 
 
13
type proxySuite struct {
 
14
        testbase.LoggingSuite
 
15
}
 
16
 
 
17
var _ = gc.Suite(&proxySuite{})
 
18
 
 
19
func (s *proxySuite) TestDetectNoSettings(c *gc.C) {
 
20
        // Patch all of the environment variables we check out just in case the
 
21
        // user has one set.
 
22
        s.PatchEnvironment("http_proxy", "")
 
23
        s.PatchEnvironment("HTTP_PROXY", "")
 
24
        s.PatchEnvironment("https_proxy", "")
 
25
        s.PatchEnvironment("HTTPS_PROXY", "")
 
26
        s.PatchEnvironment("ftp_proxy", "")
 
27
        s.PatchEnvironment("FTP_PROXY", "")
 
28
 
 
29
        proxies := osenv.DetectProxies()
 
30
 
 
31
        c.Assert(proxies, gc.DeepEquals, osenv.ProxySettings{})
 
32
}
 
33
 
 
34
func (s *proxySuite) TestDetectPrimary(c *gc.C) {
 
35
        // Patch all of the environment variables we check out just in case the
 
36
        // user has one set.
 
37
        s.PatchEnvironment("http_proxy", "http://user@10.0.0.1")
 
38
        s.PatchEnvironment("HTTP_PROXY", "")
 
39
        s.PatchEnvironment("https_proxy", "https://user@10.0.0.1")
 
40
        s.PatchEnvironment("HTTPS_PROXY", "")
 
41
        s.PatchEnvironment("ftp_proxy", "ftp://user@10.0.0.1")
 
42
        s.PatchEnvironment("FTP_PROXY", "")
 
43
 
 
44
        proxies := osenv.DetectProxies()
 
45
 
 
46
        c.Assert(proxies, gc.DeepEquals, osenv.ProxySettings{
 
47
                Http:  "http://user@10.0.0.1",
 
48
                Https: "https://user@10.0.0.1",
 
49
                Ftp:   "ftp://user@10.0.0.1",
 
50
        })
 
51
}
 
52
 
 
53
func (s *proxySuite) TestDetectFallback(c *gc.C) {
 
54
        // Patch all of the environment variables we check out just in case the
 
55
        // user has one set.
 
56
        s.PatchEnvironment("http_proxy", "")
 
57
        s.PatchEnvironment("HTTP_PROXY", "http://user@10.0.0.2")
 
58
        s.PatchEnvironment("https_proxy", "")
 
59
        s.PatchEnvironment("HTTPS_PROXY", "https://user@10.0.0.2")
 
60
        s.PatchEnvironment("ftp_proxy", "")
 
61
        s.PatchEnvironment("FTP_PROXY", "ftp://user@10.0.0.2")
 
62
 
 
63
        proxies := osenv.DetectProxies()
 
64
 
 
65
        c.Assert(proxies, gc.DeepEquals, osenv.ProxySettings{
 
66
                Http:  "http://user@10.0.0.2",
 
67
                Https: "https://user@10.0.0.2",
 
68
                Ftp:   "ftp://user@10.0.0.2",
 
69
        })
 
70
}
 
71
 
 
72
func (s *proxySuite) TestDetectPrimaryPreference(c *gc.C) {
 
73
        // Patch all of the environment variables we check out just in case the
 
74
        // user has one set.
 
75
        s.PatchEnvironment("http_proxy", "http://user@10.0.0.1")
 
76
        s.PatchEnvironment("https_proxy", "https://user@10.0.0.1")
 
77
        s.PatchEnvironment("ftp_proxy", "ftp://user@10.0.0.1")
 
78
        s.PatchEnvironment("HTTP_PROXY", "http://user@10.0.0.2")
 
79
        s.PatchEnvironment("HTTPS_PROXY", "https://user@10.0.0.2")
 
80
        s.PatchEnvironment("FTP_PROXY", "ftp://user@10.0.0.2")
 
81
 
 
82
        proxies := osenv.DetectProxies()
 
83
 
 
84
        c.Assert(proxies, gc.DeepEquals, osenv.ProxySettings{
 
85
                Http:  "http://user@10.0.0.1",
 
86
                Https: "https://user@10.0.0.1",
 
87
                Ftp:   "ftp://user@10.0.0.1",
 
88
        })
 
89
}