~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/application/flags_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "github.com/juju/testing"
9
9
        jc "github.com/juju/testing/checkers"
10
10
        gc "gopkg.in/check.v1"
 
11
 
 
12
        "github.com/juju/juju/storage"
11
13
)
12
14
 
13
15
var _ = gc.Suite(&FlagSuite{})
47
49
        err = sm.Set("bar=someothervalue")
48
50
        c.Assert(err, gc.ErrorMatches, ".*duplicate.*bar.*")
49
51
}
 
52
 
 
53
func (FlagSuite) TestStorageFlag(c *gc.C) {
 
54
        var stores map[string]storage.Constraints
 
55
        flag := storageFlag{&stores, nil}
 
56
        err := flag.Set("foo=bar")
 
57
        c.Assert(err, jc.ErrorIsNil)
 
58
        c.Assert(stores, jc.DeepEquals, map[string]storage.Constraints{
 
59
                "foo": {Pool: "bar", Count: 1},
 
60
        })
 
61
}
 
62
 
 
63
func (FlagSuite) TestStorageFlagErrors(c *gc.C) {
 
64
        flag := storageFlag{new(map[string]storage.Constraints), nil}
 
65
        err := flag.Set("foo")
 
66
        c.Assert(err, gc.ErrorMatches, `expected <store>=<constraints>`)
 
67
        err = flag.Set("foo:bar=baz")
 
68
        c.Assert(err, gc.ErrorMatches, `expected <store>=<constraints>`)
 
69
        err = flag.Set("foo=")
 
70
        c.Assert(err, gc.ErrorMatches, `cannot parse disk constraints: storage constraints require at least one field to be specified`)
 
71
}
 
72
 
 
73
func (FlagSuite) TestStorageFlagBundleStorage(c *gc.C) {
 
74
        var stores map[string]storage.Constraints
 
75
        var bundleStores map[string]map[string]storage.Constraints
 
76
        flag := storageFlag{&stores, &bundleStores}
 
77
        err := flag.Set("foo=bar")
 
78
        c.Assert(err, jc.ErrorIsNil)
 
79
        err = flag.Set("app:baz=qux")
 
80
        c.Assert(err, jc.ErrorIsNil)
 
81
        c.Assert(stores, jc.DeepEquals, map[string]storage.Constraints{
 
82
                "foo": {Pool: "bar", Count: 1},
 
83
        })
 
84
        c.Assert(bundleStores, jc.DeepEquals, map[string]map[string]storage.Constraints{
 
85
                "app": map[string]storage.Constraints{
 
86
                        "baz": {Pool: "qux", Count: 1},
 
87
                },
 
88
        })
 
89
}
 
90
 
 
91
func (FlagSuite) TestStorageFlagBundleStorageErrors(c *gc.C) {
 
92
        flag := storageFlag{new(map[string]storage.Constraints), new(map[string]map[string]storage.Constraints)}
 
93
        err := flag.Set("foo")
 
94
        c.Assert(err, gc.ErrorMatches, `expected \[<application>\:]<store>=<constraints>`)
 
95
}