Skip to content

Commit

Permalink
Making name= error to force user input.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Jun 1, 2015
1 parent 0c0c83c commit 8dceeee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/juju/storage/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type tstData struct {
var errorTsts = []tstData{
{nil, ".*storage add requires a unit and a storage directive.*"},
{[]string{"tst/123"}, ".*storage add requires a unit and a storage directive.*"},
{[]string{"tst/123", "data="}, `.*storage constraints require at least one.*`},
{[]string{"tst/123", "data=-676"}, `.*count must be greater than zero, got "-676".*`},
{[]string{"tst/123", "data=676", "data=676"}, `.*storage "data" specified more than once.*`},
}
Expand Down Expand Up @@ -75,7 +76,6 @@ func (s *addSuite) TestAddInvalidUnit(c *gc.C) {
var successTsts = []tstData{
{[]string{"tst/123", "data=676"}, ""},
{[]string{"tst/123", "data"}, ``},
{[]string{"tst/123", "data="}, ``},
}

func (s *addSuite) TestAddSuccess(c *gc.C) {
Expand Down
9 changes: 3 additions & 6 deletions storage/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ func ParseStorageConstraints(args []string) (map[string]Constraints, error) {
return nil, errors.Errorf("storage %q specified more than once", parts[0])
}
if len(parts) == 1 {
// This will happen if only <name> is supplied.
parts = append(parts, "")
}
if len(parts[1]) == 0 {
//<name> is equivalent to <name>=1
parts[1] = "1"
// This will happen if only <name> is supplied which is
// equivalent to <name>=1
parts = append(parts, "1")
}
cons, err := ParseConstraints(parts[1])
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions storage/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ func (s *ConstraintsSuite) TestParseStorageConstraints(c *gc.C) {
Count: 1,
}})
s.testParseStorageConstraints(c,
[]string{"data="},
map[string]storage.Constraints{"data": storage.Constraints{
Count: 1,
}})
s.testParseStorageConstraints(c,
[]string{"data=", "cache"},
[]string{"data", "cache"},
map[string]storage.Constraints{
"data": storage.Constraints{
Count: 1,
Expand All @@ -144,6 +139,9 @@ func (s *ConstraintsSuite) TestParseStorageConstraintsErrors(c *gc.C) {
s.testStorageConstraintsError(c,
[]string{"data=-1"},
`.*cannot parse constraints for storage "data".*`)
s.testStorageConstraintsError(c,
[]string{"data="},
`.*cannot parse constraints for storage "data".*`)
}

func (*ConstraintsSuite) testParseStorageConstraints(c *gc.C,
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/storage-add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *storageAddSuite) TestStorageAddInit(c *gc.C) {
tests := []tstData{
{[]string{}, 1, "storage add requires a storage directive"},
{[]string{"data=-676"}, 1, `.*cannot parse count: count must be gre.*`},
{[]string{"data="}, 1, ".*storage constraints require at least one.*"},
}
for i, t := range tests {
c.Logf("test %d: %#v", i, t.args)
Expand All @@ -69,7 +70,6 @@ func (s *storageAddSuite) TestAddUnitStorage(c *gc.C) {
tests := []tstData{
{[]string{"data=676"}, 0, ""},
{[]string{"data"}, 0, ``},
{[]string{"data="}, 0, ""},
}

for i, t := range tests {
Expand Down

0 comments on commit 8dceeee

Please sign in to comment.