11
11
gc "launchpad.net/gocheck"
14
13
"launchpad.net/juju-core/container/lxc/mock"
14
"launchpad.net/juju-core/testing/testbase"
17
// SetContainerDir allows tests in other packages to override the
19
func SetContainerDir(dir string) (old string) {
20
old, containerDir = containerDir, dir
24
// SetLxcContainerDir allows tests in other packages to override the
26
func SetLxcContainerDir(dir string) (old string) {
27
old, lxcContainerDir = lxcContainerDir, dir
31
// SetLxcRestartDir allows tests in other packages to override the
32
// lxcRestartDir, which contains the symlinks to the config files so
33
// containers can be auto-restarted on reboot.
34
func SetLxcRestartDir(dir string) (old string) {
35
old, lxcRestartDir = lxcRestartDir, dir
39
// SetRemovedContainerDir allows tests in other packages to override the
40
// removedContainerDir.
41
func SetRemovedContainerDir(dir string) (old string) {
42
old, removedContainerDir = removedContainerDir, dir
46
// SetLxcFactory allows tests in other packages to override the lxcObjectFactory
47
func SetLxcFactory(factory golxc.ContainerFactory) (old golxc.ContainerFactory) {
48
logger.Infof("lxcObjectFactory replaced with %v", factory)
49
old, lxcObjectFactory = lxcObjectFactory, factory
53
17
// TestSuite replaces the lxc factory that the broker uses with a mock
55
19
type TestSuite struct {
56
Factory mock.ContainerFactory
57
oldFactory golxc.ContainerFactory
62
oldContainerDir string
64
oldLxcContainerDir string
21
Factory mock.ContainerFactory
68
func (s *TestSuite) SetUpSuite(c *gc.C) {}
70
func (s *TestSuite) TearDownSuite(c *gc.C) {}
72
28
func (s *TestSuite) SetUpTest(c *gc.C) {
29
s.LoggingSuite.SetUpTest(c)
73
30
s.ContainerDir = c.MkDir()
74
s.oldContainerDir = SetContainerDir(s.ContainerDir)
31
s.PatchValue(&containerDir, s.ContainerDir)
75
32
s.RemovedDir = c.MkDir()
76
s.oldRemovedDir = SetRemovedContainerDir(s.RemovedDir)
33
s.PatchValue(&removedContainerDir, s.RemovedDir)
77
34
s.LxcDir = c.MkDir()
78
s.oldLxcContainerDir = SetLxcContainerDir(s.LxcDir)
35
s.PatchValue(&lxcContainerDir, s.LxcDir)
79
36
s.RestartDir = c.MkDir()
80
s.oldRestartDir = SetLxcRestartDir(s.RestartDir)
37
s.PatchValue(&lxcRestartDir, s.RestartDir)
81
38
s.Factory = mock.MockFactory()
82
s.oldFactory = SetLxcFactory(s.Factory)
85
func (s *TestSuite) TearDownTest(c *gc.C) {
86
SetContainerDir(s.oldContainerDir)
87
SetLxcContainerDir(s.oldLxcContainerDir)
88
SetRemovedContainerDir(s.oldRemovedDir)
89
SetLxcFactory(s.oldFactory)
39
s.PatchValue(&lxcObjectFactory, s.Factory)