~sinzui/ubuntu/vivid/juju-core/vivid-1.24.6

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/service/common/conf_test.go

  • Committer: Curtis Hovey
  • Date: 2015-09-30 14:14:54 UTC
  • mfrom: (1.1.34)
  • Revision ID: curtis@hovey.name-20150930141454-o3ldf23dzyjio6c0
Backport of 1.24.6 from wily. (LP: #1500916)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package common_test
 
5
 
 
6
import (
 
7
        "github.com/juju/testing"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        "github.com/juju/utils/shell"
 
10
        gc "gopkg.in/check.v1"
 
11
 
 
12
        "github.com/juju/juju/service/common"
 
13
)
 
14
 
 
15
var renderer = &shell.BashRenderer{}
 
16
 
 
17
type confSuite struct {
 
18
        testing.IsolationSuite
 
19
}
 
20
 
 
21
var _ = gc.Suite(&confSuite{})
 
22
 
 
23
func (*confSuite) TestIsZeroTrue(c *gc.C) {
 
24
        var conf common.Conf
 
25
        isZero := conf.IsZero()
 
26
 
 
27
        c.Check(isZero, jc.IsTrue)
 
28
}
 
29
 
 
30
func (*confSuite) TestIsZero(c *gc.C) {
 
31
        conf := common.Conf{
 
32
                Desc:      "some service",
 
33
                ExecStart: "/path/to/some-command a b c",
 
34
        }
 
35
        isZero := conf.IsZero()
 
36
 
 
37
        c.Check(isZero, jc.IsFalse)
 
38
}
 
39
 
 
40
func (*confSuite) TestValidateOkay(c *gc.C) {
 
41
        conf := common.Conf{
 
42
                Desc:      "some service",
 
43
                ExecStart: "/path/to/some-command a b c",
 
44
        }
 
45
        err := conf.Validate(renderer)
 
46
 
 
47
        c.Check(err, jc.ErrorIsNil)
 
48
}
 
49
 
 
50
func (*confSuite) TestValidateSingleQuotedExecutable(c *gc.C) {
 
51
        conf := common.Conf{
 
52
                Desc:      "some service",
 
53
                ExecStart: "'/path/to/some-command' a b c",
 
54
        }
 
55
        err := conf.Validate(renderer)
 
56
 
 
57
        c.Check(err, jc.ErrorIsNil)
 
58
}
 
59
 
 
60
func (*confSuite) TestValidateDoubleQuotedExecutable(c *gc.C) {
 
61
        conf := common.Conf{
 
62
                Desc:      "some service",
 
63
                ExecStart: `"/path/to/some-command" a b c`,
 
64
        }
 
65
        err := conf.Validate(renderer)
 
66
 
 
67
        c.Check(err, jc.ErrorIsNil)
 
68
}
 
69
 
 
70
func (*confSuite) TestValidatePartiallyQuotedExecutable(c *gc.C) {
 
71
        conf := common.Conf{
 
72
                Desc:      "some service",
 
73
                ExecStart: "'/path/to/some-command a b c'",
 
74
        }
 
75
        err := conf.Validate(renderer)
 
76
 
 
77
        c.Check(err, gc.ErrorMatches, `.*relative path in ExecStart \(.*`)
 
78
}
 
79
 
 
80
func (*confSuite) TestValidateMissingDesc(c *gc.C) {
 
81
        conf := common.Conf{
 
82
                ExecStart: "/path/to/some-command a b c",
 
83
        }
 
84
        err := conf.Validate(renderer)
 
85
 
 
86
        c.Check(err, gc.ErrorMatches, ".*missing Desc.*")
 
87
}
 
88
 
 
89
func (*confSuite) TestValidateMissingExecStart(c *gc.C) {
 
90
        conf := common.Conf{
 
91
                Desc: "some service",
 
92
        }
 
93
        err := conf.Validate(renderer)
 
94
 
 
95
        c.Check(err, gc.ErrorMatches, ".*missing ExecStart.*")
 
96
}
 
97
 
 
98
func (*confSuite) TestValidateRelativeExecStart(c *gc.C) {
 
99
        conf := common.Conf{
 
100
                Desc:      "some service",
 
101
                ExecStart: "some-command a b c",
 
102
        }
 
103
        err := conf.Validate(renderer)
 
104
 
 
105
        c.Check(err, gc.ErrorMatches, `.*relative path in ExecStart \(.*`)
 
106
}
 
107
 
 
108
func (*confSuite) TestValidateRelativeExecStopPost(c *gc.C) {
 
109
        conf := common.Conf{
 
110
                Desc:         "some service",
 
111
                ExecStart:    "/path/to/some-command a b c",
 
112
                ExecStopPost: "some-other-command a b c",
 
113
        }
 
114
        err := conf.Validate(renderer)
 
115
 
 
116
        c.Check(err, gc.ErrorMatches, `.*relative path in ExecStopPost \(.*`)
 
117
}