github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/description/linklayerdevice_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 LinkLayerDeviceSerializationSuite struct {
    13  	SliceSerializationSuite
    14  }
    15  
    16  var _ = gc.Suite(&LinkLayerDeviceSerializationSuite{})
    17  
    18  func (s *LinkLayerDeviceSerializationSuite) SetUpTest(c *gc.C) {
    19  	s.SliceSerializationSuite.SetUpTest(c)
    20  	s.importName = "link-layer-devices"
    21  	s.sliceName = "link-layer-devices"
    22  	s.importFunc = func(m map[string]interface{}) (interface{}, error) {
    23  		return importLinkLayerDevices(m)
    24  	}
    25  	s.testFields = func(m map[string]interface{}) {
    26  		m["link-layer-devices"] = []interface{}{}
    27  	}
    28  }
    29  
    30  func (s *LinkLayerDeviceSerializationSuite) TestNewLinkLayerDevice(c *gc.C) {
    31  	args := LinkLayerDeviceArgs{
    32  		ProviderID:  "magic",
    33  		MachineID:   "bar",
    34  		Name:        "foo",
    35  		MTU:         54,
    36  		Type:        "loopback",
    37  		MACAddress:  "DEADBEEF",
    38  		IsAutoStart: true,
    39  		IsUp:        true,
    40  		ParentName:  "bam",
    41  	}
    42  	device := newLinkLayerDevice(args)
    43  	c.Assert(device.ProviderID(), gc.Equals, args.ProviderID)
    44  	c.Assert(device.MachineID(), gc.Equals, args.MachineID)
    45  	c.Assert(device.Name(), gc.Equals, args.Name)
    46  	c.Assert(device.MTU(), gc.Equals, args.MTU)
    47  	c.Assert(device.Type(), gc.Equals, args.Type)
    48  	c.Assert(device.MACAddress(), gc.Equals, args.MACAddress)
    49  	c.Assert(device.IsAutoStart(), gc.Equals, args.IsAutoStart)
    50  	c.Assert(device.IsUp(), gc.Equals, args.IsUp)
    51  	c.Assert(device.ParentName(), gc.Equals, args.ParentName)
    52  }
    53  
    54  func (s *LinkLayerDeviceSerializationSuite) TestParsingSerializedData(c *gc.C) {
    55  	initial := linklayerdevices{
    56  		Version: 1,
    57  		LinkLayerDevices_: []*linklayerdevice{
    58  			newLinkLayerDevice(LinkLayerDeviceArgs{
    59  				ProviderID:  "magic",
    60  				MachineID:   "bar",
    61  				Name:        "foo",
    62  				MTU:         54,
    63  				Type:        "loopback",
    64  				MACAddress:  "DEADBEEF",
    65  				IsAutoStart: true,
    66  				IsUp:        true,
    67  				ParentName:  "bam",
    68  			}),
    69  			newLinkLayerDevice(LinkLayerDeviceArgs{Name: "weeee"}),
    70  		},
    71  	}
    72  
    73  	bytes, err := yaml.Marshal(initial)
    74  	c.Assert(err, jc.ErrorIsNil)
    75  
    76  	var source map[string]interface{}
    77  	err = yaml.Unmarshal(bytes, &source)
    78  	c.Assert(err, jc.ErrorIsNil)
    79  
    80  	devices, err := importLinkLayerDevices(source)
    81  	c.Assert(err, jc.ErrorIsNil)
    82  
    83  	c.Assert(devices, jc.DeepEquals, initial.LinkLayerDevices_)
    84  }