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" |
8 "testing" | 9 "testing" |
9 ) | 10 ) |
10 | 11 |
11 func Test(t *testing.T) { TestingT(t) } | 12 func Test(t *testing.T) { TestingT(t) } |
12 | 13 |
14 type EnvironSuite struct{} | |
15 | |
16 var _ = Suite(&EnvironSuite{}) | |
17 | |
18 var lxcfile = `# MIRROR to be used by ubuntu template at container creation: | |
19 # Leaving it undefined is fine | |
20 #MIRROR="http://archive.ubuntu.com/ubuntu" | |
21 # or· | |
22 #MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu" | |
23 | |
24 # LXC_AUTO - whether or not to start containers symlinked under | |
25 # /etc/lxc/auto | |
26 LXC_AUTO="true" | |
27 | |
28 # Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your | |
29 # containers. Set to "false" if you'll use virbr0 or another existing | |
30 # bridge, or mavlan to your host's NIC. | |
31 USE_LXC_BRIDGE="true" | |
32 | |
33 # LXC_BRIDGE and LXC_ADDR are changed against original for | |
34 # testing purposes. | |
35 LXC_BRIDGE="lxcbr9" | |
36 LXC_ADDR="10.0.9.1" | |
37 LXC_NETMASK="255.255.255.0" | |
38 LXC_NETWORK="10.0.9.0/24" | |
39 LXC_DHCP_RANGE="10.0.9.2,10.0.9.254" | |
40 LXC_DHCP_MAX="253" | |
41 | |
42 LXC_SHUTDOWN_TIMEOUT=120` | |
43 | |
44 func (s *EnvironSuite) TestReadDefaultEnviron(c *C) { | |
45 // Test reading the environment. | |
46 f, err := ioutil.TempFile("/tmp", "lxc-test") | |
fwereade
2013/01/30 16:37:39
c.MkDir()
TheMue
2013/01/31 15:54:11
Done.
| |
47 c.Assert(err, IsNil) | |
48 defer func() { | |
49 c.Assert(os.Remove(f.Name()), IsNil) | |
50 }() | |
51 _, err = f.WriteString(lxcfile) | |
52 c.Assert(err, IsNil) | |
53 c.Assert(f.Close(), IsNil) | |
54 | |
55 orig := golxc.SetLXCDefaultFile(f.Name()) | |
56 defer golxc.SetLXCDefaultFile(orig) | |
57 | |
58 env, err := golxc.ReadDefaultEnviron() | |
59 c.Assert(err, IsNil) | |
60 c.Assert(len(env), Equals, 9) | |
fwereade
2013/01/30 16:37:39
A `DeepEquals, map[string]string{...}` here might
TheMue
2013/01/31 15:54:11
Done.
| |
61 c.Assert(env["MIRROR"], Equals, "") | |
62 c.Assert(env["LXC_AUTO"], Equals, "true") | |
63 c.Assert(env["USE_LXC_BRIDGE"], Equals, "true") | |
64 c.Assert(env["LXC_BRIDGE"], Equals, "lxcbr9") | |
65 c.Assert(env["LXC_ADDR"], Equals, "10.0.9.1") | |
66 c.Assert(env["LXC_NETMASK"], Equals, "255.255.255.0") | |
67 c.Assert(env["LXC_NETWORK"], Equals, "10.0.9.0/24") | |
68 c.Assert(env["LXC_DHCP_RANGE"], Equals, "10.0.9.2,10.0.9.254") | |
69 c.Assert(env["LXC_DHCP_MAX"], Equals, "253") | |
70 c.Assert(env["LXC_SHUTDOWN_TIMEOUT"], Equals, "120") | |
71 } | |
72 | |
73 func (s *EnvironSuite) TestReadNotExistingDefaultEnviron(c *C) { | |
74 // Test reading a not existing environment. | |
75 orig := golxc.SetLXCDefaultFile("/tmp/not-existing-exc-test") | |
fwereade
2013/01/30 16:37:39
filepath.Join(c.MkDir(), "does-not-exist")
TheMue
2013/01/31 15:54:11
File isn't created, can be any non-existing name.
fwereade
2013/02/07 09:43:11
Please make sure we're consistent with the other b
| |
76 defer golxc.SetLXCDefaultFile(orig) | |
77 | |
78 _, err := golxc.ReadDefaultEnviron() | |
79 c.Assert(err, ErrorMatches, "error executing .*: Can't open /tmp/not-exi sting-exc-test") | |
80 } | |
81 | |
13 type LXCSuite struct{} | 82 type LXCSuite struct{} |
14 | 83 |
15 var _ = Suite(&LXCSuite{}) | 84 var _ = Suite(&LXCSuite{}) |
16 | 85 |
17 func (s *LXCSuite) SetUpSuite(c *C) { | 86 func (s *LXCSuite) SetUpSuite(c *C) { |
18 u, err := user.Current() | 87 u, err := user.Current() |
19 c.Assert(err, IsNil) | 88 c.Assert(err, IsNil) |
20 if u.Uid != "0" { | 89 if u.Uid != "0" { |
21 // Has to be run as root! | 90 // Has to be run as root! |
22 c.Skip("tests must run as root") | 91 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) | 307 c.Assert(lc.Create("ubuntu"), IsNil) |
239 defer func() { | 308 defer func() { |
240 c.Assert(lc.Destroy(), IsNil) | 309 c.Assert(lc.Destroy(), IsNil) |
241 }() | 310 }() |
242 c.Assert(lc.Start("", ""), IsNil) | 311 c.Assert(lc.Start("", ""), IsNil) |
243 defer func() { | 312 defer func() { |
244 c.Assert(lc.Stop(), IsNil) | 313 c.Assert(lc.Stop(), IsNil) |
245 }() | 314 }() |
246 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") | 315 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") |
247 } | 316 } |
OLD | NEW |