Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5410)

Delta Between Two Patch Sets: golxc_test.go

Issue 6853075: golxc: added configuration reading (Closed)
Left Patch Set: golxc: added configuration reading Created 11 years, 1 month ago
Right Patch Set: golxc: added configuration reading Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « export_test.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package golxc_test 1 package golxc_test
2 2
3 import ( 3 import (
4 "fmt"
5 "io/ioutil" 4 "io/ioutil"
6 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
7 "os" 6 "os"
8 "os/user" 7 "os/user"
9 "path/filepath" 8 "path/filepath"
10 "testing" 9 "testing"
11 10
12 "launchpad.net/golxc" 11 "launchpad.net/golxc"
13 ) 12 )
14 13
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 var lxcconf = map[string]string{ 49 var lxcconf = map[string]string{
51 "address": "10.0.9.1", 50 "address": "10.0.9.1",
52 "bridge": "lxcbr9", 51 "bridge": "lxcbr9",
53 } 52 }
54 53
55 func (s *ConfigSuite) TestReadConf(c *C) { 54 func (s *ConfigSuite) TestReadConf(c *C) {
56 // Test reading the configuration. 55 // Test reading the configuration.
57 cf := filepath.Join(c.MkDir(), "lxc-test") 56 cf := filepath.Join(c.MkDir(), "lxc-test")
58 c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil) 57 c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil)
59 58
60 » orig := golxc.SetConfPath(cf) 59 » defer golxc.SetConfPath(golxc.SetConfPath(cf))
61 » defer golxc.SetConfPath(orig)
fwereade 2013/02/07 09:43:11 Hey, you could do: defer golxc.SetConfPath(golxc.
TheMue 2013/02/07 11:39:18 Done.
62 60
63 conf, err := golxc.ReadConf() 61 conf, err := golxc.ReadConf()
64 c.Assert(err, IsNil) 62 c.Assert(err, IsNil)
65 c.Assert(conf, DeepEquals, lxcconf) 63 c.Assert(conf, DeepEquals, lxcconf)
66 } 64 }
67 65
68 func (s *ConfigSuite) TestReadNotExistingDefaultEnviron(c *C) { 66 func (s *ConfigSuite) TestReadNotExistingDefaultEnviron(c *C) {
69 // Test reading a not existing environment. 67 // Test reading a not existing environment.
70 » orig := golxc.SetConfPath(nonExistingPath()) 68 » defer golxc.SetConfPath(golxc.SetConfPath(filepath.Join(c.MkDir(), "foo" )))
71 » defer golxc.SetConfPath(orig)
72 69
73 _, err := golxc.ReadConf() 70 _, err := golxc.ReadConf()
74 c.Assert(err, ErrorMatches, "open .*: no such file or directory") 71 c.Assert(err, ErrorMatches, "open .*: no such file or directory")
75 }
76
77 func nonExistingPath() string {
78 base := "/any/path/to/non-existing/lxc-file-%d"
79 index := 0
80 for {
81 path := fmt.Sprintf(base, index)
82 f, err := os.Open(path)
83 if os.IsNotExist(err) {
84 return path
85 }
86 f.Close()
87 index++
88 }
89 panic("unreachable")
90 } 72 }
91 73
92 type LXCSuite struct{} 74 type LXCSuite struct{}
93 75
94 var _ = Suite(&LXCSuite{}) 76 var _ = Suite(&LXCSuite{})
95 77
96 func (s *LXCSuite) SetUpSuite(c *C) { 78 func (s *LXCSuite) SetUpSuite(c *C) {
97 u, err := user.Current() 79 u, err := user.Current()
98 c.Assert(err, IsNil) 80 c.Assert(err, IsNil)
99 if u.Uid != "0" { 81 if u.Uid != "0" {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 c.Assert(lc.Create("ubuntu"), IsNil) 299 c.Assert(lc.Create("ubuntu"), IsNil)
318 defer func() { 300 defer func() {
319 c.Assert(lc.Destroy(), IsNil) 301 c.Assert(lc.Destroy(), IsNil)
320 }() 302 }()
321 c.Assert(lc.Start("", ""), IsNil) 303 c.Assert(lc.Start("", ""), IsNil)
322 defer func() { 304 defer func() {
323 c.Assert(lc.Stop(), IsNil) 305 c.Assert(lc.Stop(), IsNil)
324 }() 306 }()
325 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") 307 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen")
326 } 308 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b