-
Notifications
You must be signed in to change notification settings - Fork 33
/
stringmap_test.go
61 lines (50 loc) · 1.6 KB
/
stringmap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package cmd_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/cmd/v4"
)
var _ = gc.Suite(&StringMapSuite{})
type StringMapSuite struct {
testing.IsolationSuite
}
func (StringMapSuite) TestStringMapNilOk(c *gc.C) {
// note that the map may start out nil
var values map[string]string
c.Assert(values, gc.IsNil)
sm := cmd.StringMap{Mapping: &values}
err := sm.Set("foo=foovalue")
c.Assert(err, jc.ErrorIsNil)
err = sm.Set("bar=barvalue")
c.Assert(err, jc.ErrorIsNil)
// now the map is non-nil and filled
c.Assert(values, gc.DeepEquals, map[string]string{
"foo": "foovalue",
"bar": "barvalue",
})
}
func (StringMapSuite) TestStringMapBadVal(c *gc.C) {
sm := cmd.StringMap{Mapping: &map[string]string{}}
err := sm.Set("foo")
c.Assert(err, gc.ErrorMatches, "expected key=value format")
}
func (StringMapSuite) TestStringMapDupVal(c *gc.C) {
sm := cmd.StringMap{Mapping: &map[string]string{}}
err := sm.Set("bar=somevalue")
c.Assert(err, jc.ErrorIsNil)
err = sm.Set("bar=someothervalue")
c.Assert(err, gc.ErrorMatches, "duplicate key specified")
}
func (StringMapSuite) TestStringMapNoValue(c *gc.C) {
sm := cmd.StringMap{Mapping: &map[string]string{}}
err := sm.Set("bar=")
c.Assert(err, gc.ErrorMatches, "key and value must be non-empty")
}
func (StringMapSuite) TestStringMapNoKey(c *gc.C) {
sm := cmd.StringMap{Mapping: &map[string]string{}}
err := sm.Set("=bar")
c.Assert(err, gc.ErrorMatches, "key and value must be non-empty")
}