github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/juju/action/common_test.go (about)

     1  // Copyright 2014-2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package action_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/cmd/juju/action"
    11  )
    12  
    13  type CommonSuite struct{}
    14  
    15  var _ = gc.Suite(&CommonSuite{})
    16  
    17  type insertSliceValue struct {
    18  	valuePath []string
    19  	value     interface{}
    20  }
    21  
    22  func (s *CommonSuite) TestAddValueToMap(c *gc.C) {
    23  	for i, t := range []struct {
    24  		should       string
    25  		startingMap  map[string]interface{}
    26  		insertSlices []insertSliceValue
    27  		expectedMap  map[string]interface{}
    28  	}{{
    29  		should: "insert a couple of values",
    30  		startingMap: map[string]interface{}{
    31  			"foo": "bar",
    32  			"bar": map[string]interface{}{
    33  				"baz": "bo",
    34  				"bur": "bor",
    35  			},
    36  		},
    37  		insertSlices: []insertSliceValue{
    38  			{
    39  				valuePath: []string{"well", "now"},
    40  				value:     5,
    41  			},
    42  			{
    43  				valuePath: []string{"foo"},
    44  				value:     "kek",
    45  			},
    46  		},
    47  		expectedMap: map[string]interface{}{
    48  			"foo": "kek",
    49  			"bar": map[string]interface{}{
    50  				"baz": "bo",
    51  				"bur": "bor",
    52  			},
    53  			"well": map[string]interface{}{
    54  				"now": 5,
    55  			},
    56  		},
    57  	}} {
    58  		c.Logf("test %d: should %s", i, t.should)
    59  		for _, sVal := range t.insertSlices {
    60  			action.AddValueToMap(sVal.valuePath, sVal.value, t.startingMap)
    61  		}
    62  		// note addValueToMap mutates target.
    63  		c.Check(t.startingMap, jc.DeepEquals, t.expectedMap)
    64  	}
    65  }