github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/description/space_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package description
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/yaml.v2"
    10  )
    11  
    12  type SpaceSerializationSuite struct {
    13  	SliceSerializationSuite
    14  }
    15  
    16  var _ = gc.Suite(&SpaceSerializationSuite{})
    17  
    18  func (s *SpaceSerializationSuite) SetUpTest(c *gc.C) {
    19  	s.SliceSerializationSuite.SetUpTest(c)
    20  	s.importName = "spaces"
    21  	s.sliceName = "spaces"
    22  	s.importFunc = func(m map[string]interface{}) (interface{}, error) {
    23  		return importSpaces(m)
    24  	}
    25  	s.testFields = func(m map[string]interface{}) {
    26  		m["spaces"] = []interface{}{}
    27  	}
    28  }
    29  
    30  func (s *SpaceSerializationSuite) TestNewSpace(c *gc.C) {
    31  	args := SpaceArgs{
    32  		Name:       "special",
    33  		Public:     true,
    34  		ProviderID: "magic",
    35  	}
    36  	space := newSpace(args)
    37  	c.Assert(space.Name(), gc.Equals, args.Name)
    38  	c.Assert(space.Public(), gc.Equals, args.Public)
    39  	c.Assert(space.ProviderID(), gc.Equals, args.ProviderID)
    40  }
    41  
    42  func (s *SpaceSerializationSuite) TestParsingSerializedData(c *gc.C) {
    43  	initial := spaces{
    44  		Version: 1,
    45  		Spaces_: []*space{
    46  			newSpace(SpaceArgs{
    47  				Name:       "special",
    48  				Public:     true,
    49  				ProviderID: "magic",
    50  			}),
    51  			newSpace(SpaceArgs{Name: "foo"}),
    52  		},
    53  	}
    54  
    55  	bytes, err := yaml.Marshal(initial)
    56  	c.Assert(err, jc.ErrorIsNil)
    57  
    58  	var source map[string]interface{}
    59  	err = yaml.Unmarshal(bytes, &source)
    60  	c.Assert(err, jc.ErrorIsNil)
    61  
    62  	spaces, err := importSpaces(source)
    63  	c.Assert(err, jc.ErrorIsNil)
    64  
    65  	c.Assert(spaces, jc.DeepEquals, initial.Spaces_)
    66  }