1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
8
"github.com/juju/testing"
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
13
var _ = gc.Suite(&FlagSuite{})
15
type FlagSuite struct {
16
testing.IsolationSuite
19
func (FlagSuite) TestStringMapNilOk(c *gc.C) {
20
// note that the map may start out nil
21
var values map[string]string
22
c.Assert(values, gc.IsNil)
23
sm := stringMap{&values}
24
err := sm.Set("foo=foovalue")
25
c.Assert(err, jc.ErrorIsNil)
26
err = sm.Set("bar=barvalue")
27
c.Assert(err, jc.ErrorIsNil)
29
// now the map is non-nil and filled
30
c.Assert(values, gc.DeepEquals, map[string]string{
36
func (FlagSuite) TestStringMapBadVal(c *gc.C) {
37
sm := stringMap{&map[string]string{}}
39
c.Assert(err, jc.Satisfies, errors.IsNotValid)
40
c.Assert(err, gc.ErrorMatches, "badly formatted name value pair: foo")
43
func (FlagSuite) TestStringMapDupVal(c *gc.C) {
44
sm := stringMap{&map[string]string{}}
45
err := sm.Set("bar=somevalue")
46
c.Assert(err, jc.ErrorIsNil)
47
err = sm.Set("bar=someothervalue")
48
c.Assert(err, gc.ErrorMatches, ".*duplicate.*bar.*")