Left: | ||
Right: |
OLD | NEW |
---|---|
1 package golxc_test | 1 package golxc_test |
2 | 2 |
3 import ( | 3 import ( |
4 "io/ioutil" | |
4 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
5 "launchpad.net/golxc" | 6 "launchpad.net/golxc" |
6 "os" | 7 "os" |
7 "os/user" | 8 "os/user" |
9 "path/filepath" | |
8 "testing" | 10 "testing" |
9 ) | 11 ) |
10 | 12 |
11 func Test(t *testing.T) { TestingT(t) } | 13 func Test(t *testing.T) { TestingT(t) } |
12 | 14 |
15 type EnvironSuite struct{} | |
16 | |
17 var _ = Suite(&EnvironSuite{}) | |
18 | |
19 var lxcfile = `# MIRROR to be used by ubuntu template at container creation: | |
20 # Leaving it undefined is fine | |
21 #MIRROR="http://archive.ubuntu.com/ubuntu" | |
22 # or· | |
23 #MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu" | |
24 | |
25 # LXC_AUTO - whether or not to start containers symlinked under | |
26 # /etc/lxc/auto | |
27 LXC_AUTO="true" | |
28 | |
29 # Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your | |
30 # containers. Set to "false" if you'll use virbr0 or another existing | |
31 # bridge, or mavlan to your host's NIC. | |
32 USE_LXC_BRIDGE="true" | |
33 | |
34 # LXC_BRIDGE and LXC_ADDR are changed against original for | |
35 # testing purposes. | |
36 LXC_BRIDGE="lxcbr9" | |
fwereade
2013/02/04 14:58:14
Add a commented-out LXC_BRIDGE line somewhere befo
TheMue
2013/02/05 12:47:53
Done.
| |
37 LXC_ADDR="10.0.9.1" | |
fwereade
2013/02/04 14:58:14
Ditto here, check for values that are close but do
TheMue
2013/02/05 12:47:53
Done.
| |
38 LXC_NETMASK="255.255.255.0" | |
39 LXC_NETWORK="10.0.9.0/24" | |
40 LXC_DHCP_RANGE="10.0.9.2,10.0.9.254" | |
41 LXC_DHCP_MAX="253" | |
42 | |
43 LXC_SHUTDOWN_TIMEOUT=120` | |
44 | |
45 var lxcconf = map[string]string{ | |
46 "address": "10.0.9.1", | |
47 "bridge": "lxcbr9", | |
48 } | |
49 | |
50 func (s *EnvironSuite) TestReadConf(c *C) { | |
51 // Test reading the configuration. | |
52 cf := filepath.Join(c.MkDir(), "lxc-test") | |
53 c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil) | |
54 | |
55 orig := golxc.SetConfFile(cf) | |
56 defer golxc.SetConfFile(orig) | |
57 | |
58 conf, err := golxc.ReadConf() | |
59 c.Assert(err, IsNil) | |
60 c.Assert(conf, DeepEquals, lxcconf) | |
61 } | |
62 | |
63 func (s *EnvironSuite) TestReadNotExistingDefaultEnviron(c *C) { | |
64 // Test reading a not existing environment. | |
65 orig := golxc.SetConfFile("/any/path/to/non-existing/lxc-file") | |
66 defer golxc.SetConfFile(orig) | |
67 | |
68 _, err := golxc.ReadConf() | |
69 c.Assert(err, ErrorMatches, "open /any/path/to/non-existing/lxc-file: no such file or directory") | |
70 } | |
71 | |
13 type LXCSuite struct{} | 72 type LXCSuite struct{} |
14 | 73 |
15 var _ = Suite(&LXCSuite{}) | 74 var _ = Suite(&LXCSuite{}) |
16 | 75 |
17 func (s *LXCSuite) SetUpSuite(c *C) { | 76 func (s *LXCSuite) SetUpSuite(c *C) { |
18 u, err := user.Current() | 77 u, err := user.Current() |
19 c.Assert(err, IsNil) | 78 c.Assert(err, IsNil) |
20 if u.Uid != "0" { | 79 if u.Uid != "0" { |
21 // Has to be run as root! | 80 // Has to be run as root! |
22 c.Skip("tests must run as root") | 81 c.Skip("tests must run as root") |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 c.Assert(lc.Create("ubuntu"), IsNil) | 297 c.Assert(lc.Create("ubuntu"), IsNil) |
239 defer func() { | 298 defer func() { |
240 c.Assert(lc.Destroy(), IsNil) | 299 c.Assert(lc.Destroy(), IsNil) |
241 }() | 300 }() |
242 c.Assert(lc.Start("", ""), IsNil) | 301 c.Assert(lc.Start("", ""), IsNil) |
243 defer func() { | 302 defer func() { |
244 c.Assert(lc.Stop(), IsNil) | 303 c.Assert(lc.Stop(), IsNil) |
245 }() | 304 }() |
246 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") | 305 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") |
247 } | 306 } |
OLD | NEW |