github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/service/flags_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package service 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/testing" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 ) 12 13 var _ = gc.Suite(&FlagSuite{}) 14 15 type FlagSuite struct { 16 testing.IsolationSuite 17 } 18 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) 28 29 // now the map is non-nil and filled 30 c.Assert(values, gc.DeepEquals, map[string]string{ 31 "foo": "foovalue", 32 "bar": "barvalue", 33 }) 34 } 35 36 func (FlagSuite) TestStringMapBadVal(c *gc.C) { 37 sm := stringMap{&map[string]string{}} 38 err := sm.Set("foo") 39 c.Assert(err, jc.Satisfies, errors.IsNotValid) 40 c.Assert(err, gc.ErrorMatches, "badly formatted name value pair: foo") 41 } 42 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.*") 49 }