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

« back to all changes in this revision

Viewing changes to utils/apt_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:
8
8
 
9
9
        gc "launchpad.net/gocheck"
10
10
 
 
11
        "launchpad.net/juju-core/juju/osenv"
11
12
        jc "launchpad.net/juju-core/testing/checkers"
12
13
        "launchpad.net/juju-core/testing/testbase"
13
14
        "launchpad.net/juju-core/utils"
20
21
var _ = gc.Suite(&AptSuite{})
21
22
 
22
23
func (s *AptSuite) TestOnePackage(c *gc.C) {
23
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
24
 
        defer cleanup()
 
24
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
25
25
        err := utils.AptGetInstall("test-package")
26
26
        c.Assert(err, gc.IsNil)
27
27
        cmd := <-cmdChan
37
37
        const expected = `E: frobnicator failure detected`
38
38
        cmdError := fmt.Errorf("error")
39
39
        cmdExpectedError := fmt.Errorf("apt-get failed: error")
40
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
41
 
        defer cleanup()
 
40
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
42
41
        err := utils.AptGetInstall("foo")
43
42
        c.Assert(err, gc.DeepEquals, cmdExpectedError)
44
43
        cmd := <-cmdChan
50
49
}
51
50
 
52
51
func (s *AptSuite) TestConfigProxyEmpty(c *gc.C) {
53
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
54
 
        defer cleanup()
 
52
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
55
53
        out, err := utils.AptConfigProxy()
56
54
        c.Assert(err, gc.IsNil)
57
55
        cmd := <-cmdChan
65
63
func (s *AptSuite) TestConfigProxyConfigured(c *gc.C) {
66
64
        const expected = `Acquire::http::Proxy "10.0.3.1:3142";
67
65
Acquire::https::Proxy "false";`
68
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), nil)
69
 
        defer cleanup()
 
66
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), nil)
70
67
        out, err := utils.AptConfigProxy()
71
68
        c.Assert(err, gc.IsNil)
72
69
        cmd := <-cmdChan
77
74
        c.Assert(out, gc.Equals, expected)
78
75
}
79
76
 
 
77
func (s *AptSuite) TestDetectAptProxy(c *gc.C) {
 
78
        const output = `CommandLine::AsString "apt-config dump";
 
79
Acquire::http::Proxy  "10.0.3.1:3142";
 
80
Acquire::https::Proxy "false";
 
81
Acquire::ftp::Proxy "none";
 
82
Acquire::magic::Proxy "none";
 
83
`
 
84
        _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
 
85
 
 
86
        proxy, err := utils.DetectAptProxies()
 
87
        c.Assert(err, gc.IsNil)
 
88
        c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{
 
89
                Http:  "10.0.3.1:3142",
 
90
                Https: "false",
 
91
                Ftp:   "none",
 
92
        })
 
93
}
 
94
 
 
95
func (s *AptSuite) TestDetectAptProxyNone(c *gc.C) {
 
96
        _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
 
97
        proxy, err := utils.DetectAptProxies()
 
98
        c.Assert(err, gc.IsNil)
 
99
        c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{})
 
100
}
 
101
 
 
102
func (s *AptSuite) TestDetectAptProxyPartial(c *gc.C) {
 
103
        const output = `CommandLine::AsString "apt-config dump";
 
104
Acquire::http::Proxy  "10.0.3.1:3142";
 
105
Acquire::ftp::Proxy "here-it-is";
 
106
Acquire::magic::Proxy "none";
 
107
`
 
108
        _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
 
109
 
 
110
        proxy, err := utils.DetectAptProxies()
 
111
        c.Assert(err, gc.IsNil)
 
112
        c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{
 
113
                Http: "10.0.3.1:3142",
 
114
                Ftp:  "here-it-is",
 
115
        })
 
116
}
 
117
 
80
118
func (s *AptSuite) TestConfigProxyConfiguredFilterOutput(c *gc.C) {
81
119
        const (
82
120
                output = `CommandLine::AsString "apt-config dump";
85
123
                expected = `Acquire::http::Proxy  "10.0.3.1:3142";
86
124
Acquire::https::Proxy "false";`
87
125
        )
88
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
89
 
        defer cleanup()
 
126
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
90
127
        out, err := utils.AptConfigProxy()
91
128
        c.Assert(err, gc.IsNil)
92
129
        cmd := <-cmdChan
101
138
        const expected = `E: frobnicator failure detected`
102
139
        cmdError := fmt.Errorf("error")
103
140
        cmdExpectedError := fmt.Errorf("apt-config failed: error")
104
 
        cmdChan, cleanup := testbase.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
105
 
        defer cleanup()
 
141
        cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
106
142
        out, err := utils.AptConfigProxy()
107
143
        c.Assert(err, gc.DeepEquals, cmdExpectedError)
108
144
        cmd := <-cmdChan