~juju-qa/juju-core/1.16-packaging

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/container/lxc/test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-10-10 18:07:45 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20131010180745-wuo0vv7hq7faavdk
Tags: 1.16.0-0ubuntu1
New upstream stable release (LP: #1219879).

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
import (
11
11
        gc "launchpad.net/gocheck"
12
 
        "launchpad.net/golxc"
13
12
 
14
13
        "launchpad.net/juju-core/container/lxc/mock"
 
14
        "launchpad.net/juju-core/testing/testbase"
15
15
)
16
16
 
17
 
// SetContainerDir allows tests in other packages to override the
18
 
// containerDir.
19
 
func SetContainerDir(dir string) (old string) {
20
 
        old, containerDir = containerDir, dir
21
 
        return
22
 
}
23
 
 
24
 
// SetLxcContainerDir allows tests in other packages to override the
25
 
// lxcContainerDir.
26
 
func SetLxcContainerDir(dir string) (old string) {
27
 
        old, lxcContainerDir = lxcContainerDir, dir
28
 
        return
29
 
}
30
 
 
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
36
 
        return
37
 
}
38
 
 
39
 
// SetRemovedContainerDir allows tests in other packages to override the
40
 
// removedContainerDir.
41
 
func SetRemovedContainerDir(dir string) (old string) {
42
 
        old, removedContainerDir = removedContainerDir, dir
43
 
        return
44
 
}
45
 
 
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
50
 
        return
51
 
}
52
 
 
53
17
// TestSuite replaces the lxc factory that the broker uses with a mock
54
18
// implementation.
55
19
type TestSuite struct {
56
 
        Factory            mock.ContainerFactory
57
 
        oldFactory         golxc.ContainerFactory
58
 
        ContainerDir       string
59
 
        RemovedDir         string
60
 
        LxcDir             string
61
 
        RestartDir         string
62
 
        oldContainerDir    string
63
 
        oldRemovedDir      string
64
 
        oldLxcContainerDir string
65
 
        oldRestartDir      string
 
20
        testbase.LoggingSuite
 
21
        Factory      mock.ContainerFactory
 
22
        ContainerDir string
 
23
        RemovedDir   string
 
24
        LxcDir       string
 
25
        RestartDir   string
66
26
}
67
27
 
68
 
func (s *TestSuite) SetUpSuite(c *gc.C) {}
69
 
 
70
 
func (s *TestSuite) TearDownSuite(c *gc.C) {}
71
 
 
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)
83
 
}
84
 
 
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)
90
40
}