~thumper/golxc/nicer-destroy

« back to all changes in this revision

Viewing changes to golxc_test.go

  • Committer: Frank Mueller
  • Author(s): Frank Mueller
  • Date: 2013-02-07 11:39:15 UTC
  • mfrom: (1.2.13 golxc)
  • Revision ID: themue@gmail.com-20130207113915-db9ycd5xdm2uzhqq
golxc: added configuration reading

Added the reading of configuration files, especially
the default configuration at /etc/default/lxc.

R=rog, fwereade, dfc, niemeyer
CC=
https://codereview.appspot.com/6853075

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package golxc_test
2
2
 
3
3
import (
 
4
        "io/ioutil"
4
5
        . "launchpad.net/gocheck"
5
 
        "launchpad.net/golxc"
6
6
        "os"
7
7
        "os/user"
 
8
        "path/filepath"
8
9
        "testing"
 
10
 
 
11
        "launchpad.net/golxc"
9
12
)
10
13
 
11
14
func Test(t *testing.T) { TestingT(t) }
12
15
 
 
16
type ConfigSuite struct{}
 
17
 
 
18
var _ = Suite(&ConfigSuite{})
 
19
 
 
20
var lxcfile = `# MIRROR to be used by ubuntu template at container creation:
 
21
# Leaving it undefined is fine
 
22
#MIRROR="http://archive.ubuntu.com/ubuntu"
 
23
# or 
 
24
#MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"
 
25
 
 
26
# LXC_AUTO - whether or not to start containers symlinked under
 
27
# /etc/lxc/auto
 
28
LXC_AUTO="true"
 
29
 
 
30
# Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your
 
31
# containers.  Set to "false" if you'll use virbr0 or another existing
 
32
# bridge, or mavlan to your host's NIC.
 
33
USE_LXC_BRIDGE="true"
 
34
 
 
35
# LXC_BRIDGE and LXC_ADDR are changed against original for
 
36
# testing purposes.
 
37
# LXC_BRIDGE="lxcbr1"
 
38
LXC_BRIDGE="lxcbr9"
 
39
# LXC_ADDR="10.0.1.1"
 
40
LXC_ADDR="10.0.9.1"
 
41
LXC_NETMASK="255.255.255.0"
 
42
LXC_NETWORK="10.0.9.0/24"
 
43
LXC_DHCP_RANGE="10.0.9.2,10.0.9.254"
 
44
LXC_DHCP_MAX="253"
 
45
# And for testing LXC_BRIDGE="lxcbr99" and LXC_ADDR="10.0.99.1".
 
46
 
 
47
LXC_SHUTDOWN_TIMEOUT=120`
 
48
 
 
49
var lxcconf = map[string]string{
 
50
        "address": "10.0.9.1",
 
51
        "bridge":  "lxcbr9",
 
52
}
 
53
 
 
54
func (s *ConfigSuite) TestReadConf(c *C) {
 
55
        // Test reading the configuration.
 
56
        cf := filepath.Join(c.MkDir(), "lxc-test")
 
57
        c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil)
 
58
 
 
59
        defer golxc.SetConfPath(golxc.SetConfPath(cf))
 
60
 
 
61
        conf, err := golxc.ReadConf()
 
62
        c.Assert(err, IsNil)
 
63
        c.Assert(conf, DeepEquals, lxcconf)
 
64
}
 
65
 
 
66
func (s *ConfigSuite) TestReadNotExistingDefaultEnviron(c *C) {
 
67
        // Test reading a not existing environment.
 
68
        defer golxc.SetConfPath(golxc.SetConfPath(filepath.Join(c.MkDir(), "foo")))
 
69
 
 
70
        _, err := golxc.ReadConf()
 
71
        c.Assert(err, ErrorMatches, "open .*: no such file or directory")
 
72
}
 
73
 
13
74
type LXCSuite struct{}
14
75
 
15
76
var _ = Suite(&LXCSuite{})