~chipaca/snappy/dont-panic

« back to all changes in this revision

Viewing changes to systemd/systemd_test.go

  • Committer: John R. Lenton
  • Date: 2015-04-02 22:57:40 UTC
  • mto: (289.9.4 framework-policy)
  • mto: This revision was merged to the branch mainline in revision 316.
  • Revision ID: jlenton@gmail.com-20150402225740-gi7ijj9o2uddhqiv
renamed systemctl to systemd

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 */
17
17
 
18
 
package systemctl
 
18
package systemd
19
19
 
20
20
import (
21
21
        "testing"
27
27
// Hook up gocheck into the "go test" runner
28
28
func Test(t *testing.T) { TestingT(t) }
29
29
 
30
 
// systemctl's testsuite
31
 
type SystemctlTestSuite struct {
 
30
// systemd's testsuite
 
31
type SystemdTestSuite struct {
32
32
        i      int
33
33
        argses [][]string
34
34
        errors []error
35
35
        outs   [][]byte
36
36
}
37
37
 
38
 
var _ = Suite(&SystemctlTestSuite{})
 
38
var _ = Suite(&SystemdTestSuite{})
39
39
 
40
 
func (s *SystemctlTestSuite) SetUpTest(c *C) {
 
40
func (s *SystemdTestSuite) SetUpTest(c *C) {
41
41
        SystemctlCmd = s.myRun
42
42
        s.i = 0
43
43
        s.argses = nil
45
45
        s.outs = nil
46
46
}
47
47
 
48
 
func (s *SystemctlTestSuite) TearDownTest(c *C) {
 
48
func (s *SystemdTestSuite) TearDownTest(c *C) {
49
49
        SystemctlCmd = run
50
50
}
51
51
 
52
 
func (s *SystemctlTestSuite) myRun(args ...string) (out []byte, err error) {
 
52
func (s *SystemdTestSuite) myRun(args ...string) (out []byte, err error) {
53
53
        s.argses = append(s.argses, args)
54
54
        if s.i < len(s.outs) {
55
55
                out = s.outs[s.i]
61
61
        return out, err
62
62
}
63
63
 
64
 
func (s *SystemctlTestSuite) TestDaemonReload(c *C) {
 
64
func (s *SystemdTestSuite) TestDaemonReload(c *C) {
65
65
        err := New("").DaemonReload()
66
66
        c.Assert(err, IsNil)
67
67
        c.Assert(s.argses, DeepEquals, [][]string{{"daemon-reload"}})
68
68
}
69
69
 
70
 
func (s *SystemctlTestSuite) TestStart(c *C) {
 
70
func (s *SystemdTestSuite) TestStart(c *C) {
71
71
        err := New("").Start("foo")
72
72
        c.Assert(err, IsNil)
73
73
        c.Check(s.argses, DeepEquals, [][]string{{"start", "foo"}})
74
74
}
75
75
 
76
 
func (s *SystemctlTestSuite) TestStop(c *C) {
 
76
func (s *SystemdTestSuite) TestStop(c *C) {
77
77
        s.outs = [][]byte{
78
78
                nil, // for the "stop" itself
79
79
                []byte("ActiveState=whatever\n"),
90
90
        c.Check(s.argses[1], DeepEquals, s.argses[3])
91
91
}
92
92
 
93
 
func (s *SystemctlTestSuite) TestStopTimeout(c *C) {
 
93
func (s *SystemdTestSuite) TestStopTimeout(c *C) {
94
94
        oldSteps := stopSteps
95
95
        oldDelay := stopDelay
96
96
        stopSteps = 2
104
104
        c.Assert(err, FitsTypeOf, &Timeout{})
105
105
}
106
106
 
107
 
func (s *SystemctlTestSuite) TestDisable(c *C) {
 
107
func (s *SystemdTestSuite) TestDisable(c *C) {
108
108
        err := New("xyzzy").Disable("foo")
109
109
        c.Assert(err, IsNil)
110
110
        c.Check(s.argses, DeepEquals, [][]string{{"--root", "xyzzy", "disable", "foo"}})
111
111
}
112
112
 
113
 
func (s *SystemctlTestSuite) TestEnable(c *C) {
 
113
func (s *SystemdTestSuite) TestEnable(c *C) {
114
114
        err := New("xyzzy").Enable("foo")
115
115
        c.Assert(err, IsNil)
116
116
        c.Check(s.argses, DeepEquals, [][]string{{"--root", "xyzzy", "enable", "foo"}})