Skip to content

Commit

Permalink
Simplifying impl based on review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Jun 1, 2015
1 parent 8dceeee commit 154f532
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions storage/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ func ParseStorageConstraints(args []string) (map[string]Constraints, error) {
results := make(map[string]Constraints, len(args))
for _, kv := range args {
parts := strings.SplitN(kv, "=", -1)
if len(parts) > 2 || len(parts[0]) == 0 {
name := parts[0]
if len(parts) > 2 || len(name) == 0 {
return nil, errors.Errorf(`expected "name=constraints" or "name", got %q`, kv)
}

if _, exists := results[parts[0]]; exists {
return nil, errors.Errorf("storage %q specified more than once", parts[0])
if _, exists := results[name]; exists {
return nil, errors.Errorf("storage %q specified more than once", name)
}
if len(parts) == 1 {
// This will happen if only <name> is supplied which is
// equivalent to <name>=1
parts = append(parts, "1")
consString := "1"
if len(parts) > 1 {
consString = parts[1]
}
cons, err := ParseConstraints(parts[1])
cons, err := ParseConstraints(consString)
if err != nil {
return nil, errors.Annotatef(err, "cannot parse constraints for storage %q", parts[0])
return nil, errors.Annotatef(err, "cannot parse constraints for storage %q", name)
}

results[parts[0]] = cons
results[name] = cons
}
return results, nil
}
Expand Down
4 changes: 2 additions & 2 deletions storage/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func (s *ConstraintsSuite) TestParseStorageConstraints(c *gc.C) {
Count: 1,
}})
s.testParseStorageConstraints(c,
[]string{"data", "cache"},
[]string{"data=3", "cache"},
map[string]storage.Constraints{
"data": storage.Constraints{
Count: 1,
Count: 3,
},
"cache": storage.Constraints{
Count: 1,
Expand Down

0 comments on commit 154f532

Please sign in to comment.