~juju-qa/ubuntu/yakkety/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/service/constraints_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 17:28:37 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202172837-jkrbdlyjcxtrii2n
Initial commit of 1.25.6

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 service_test
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        gc "gopkg.in/check.v1"
 
9
 
 
10
        "github.com/juju/juju/cmd/juju/service"
 
11
        "github.com/juju/juju/testing"
 
12
)
 
13
 
 
14
type ServiceConstraintsCommandsSuite struct {
 
15
        testing.FakeJujuHomeSuite
 
16
}
 
17
 
 
18
var _ = gc.Suite(&ServiceConstraintsCommandsSuite{})
 
19
 
 
20
func (s *ServiceConstraintsCommandsSuite) TestSetInit(c *gc.C) {
 
21
        for _, test := range []struct {
 
22
                args []string
 
23
                err  string
 
24
        }{
 
25
                {
 
26
                        args: []string{"--service", "mysql", "mem=4G"},
 
27
                        err:  `flag provided but not defined: --service`,
 
28
                }, {
 
29
                        args: []string{"-s", "mysql", "mem=4G"},
 
30
                        err:  `flag provided but not defined: -s`,
 
31
                }, {
 
32
                        args: []string{},
 
33
                        err:  `no service name specified`,
 
34
                }, {
 
35
                        args: []string{"mysql", "="},
 
36
                        err:  `malformed constraint "="`,
 
37
                }, {
 
38
                        args: []string{"cpu-power=250"},
 
39
                        err:  `invalid service name "cpu-power=250"`,
 
40
                }, {
 
41
                        args: []string{"mysql", "cpu-power=250"},
 
42
                },
 
43
        } {
 
44
                err := testing.InitCommand(&service.ServiceSetConstraintsCommand{}, test.args)
 
45
                if test.err == "" {
 
46
                        c.Check(err, jc.ErrorIsNil)
 
47
                } else {
 
48
                        c.Check(err, gc.ErrorMatches, test.err)
 
49
                }
 
50
        }
 
51
}
 
52
 
 
53
func (s *ServiceConstraintsCommandsSuite) TestGetInit(c *gc.C) {
 
54
        for _, test := range []struct {
 
55
                args []string
 
56
                err  string
 
57
        }{
 
58
                {
 
59
                        args: []string{"-s", "mysql"},
 
60
                        err:  `flag provided but not defined: -s`,
 
61
                }, {
 
62
                        args: []string{"--service", "mysql"},
 
63
                        err:  `flag provided but not defined: --service`,
 
64
                }, {
 
65
                        args: []string{},
 
66
                        err:  `no service name specified`,
 
67
                }, {
 
68
                        args: []string{"mysql-0"},
 
69
                        err:  `invalid service name "mysql-0"`,
 
70
                }, {
 
71
                        args: []string{"mysql"},
 
72
                },
 
73
        } {
 
74
                err := testing.InitCommand(&service.ServiceGetConstraintsCommand{}, test.args)
 
75
                if test.err == "" {
 
76
                        c.Check(err, jc.ErrorIsNil)
 
77
                } else {
 
78
                        c.Check(err, gc.ErrorMatches, test.err)
 
79
                }
 
80
        }
 
81
}