github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/payload/api/helpers_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package api
     5  
     6  import (
     7  	"github.com/juju/names"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  	"gopkg.in/juju/charm.v6-unstable"
    12  
    13  	"github.com/juju/juju/payload"
    14  )
    15  
    16  type helpersSuite struct {
    17  	testing.IsolationSuite
    18  }
    19  
    20  var _ = gc.Suite(&helpersSuite{})
    21  
    22  func (helpersSuite) TestPayload2api(c *gc.C) {
    23  	apiPayload := Payload2api(payload.FullPayloadInfo{
    24  		Payload: payload.Payload{
    25  			PayloadClass: charm.PayloadClass{
    26  				Name: "spam",
    27  				Type: "docker",
    28  			},
    29  			ID:     "idspam",
    30  			Status: payload.StateRunning,
    31  			Labels: []string{"a-tag"},
    32  			Unit:   "a-service/0",
    33  		},
    34  		Machine: "1",
    35  	})
    36  
    37  	c.Check(apiPayload, jc.DeepEquals, Payload{
    38  		Class:   "spam",
    39  		Type:    "docker",
    40  		ID:      "idspam",
    41  		Status:  payload.StateRunning,
    42  		Labels:  []string{"a-tag"},
    43  		Unit:    names.NewUnitTag("a-service/0").String(),
    44  		Machine: names.NewMachineTag("1").String(),
    45  	})
    46  }
    47  
    48  func (helpersSuite) TestAPI2Payload(c *gc.C) {
    49  	pl, err := API2Payload(Payload{
    50  		Class:   "spam",
    51  		Type:    "docker",
    52  		ID:      "idspam",
    53  		Status:  payload.StateRunning,
    54  		Labels:  []string{"a-tag"},
    55  		Unit:    names.NewUnitTag("a-service/0").String(),
    56  		Machine: names.NewMachineTag("1").String(),
    57  	})
    58  	c.Assert(err, jc.ErrorIsNil)
    59  
    60  	c.Check(pl, jc.DeepEquals, payload.FullPayloadInfo{
    61  		Payload: payload.Payload{
    62  			PayloadClass: charm.PayloadClass{
    63  				Name: "spam",
    64  				Type: "docker",
    65  			},
    66  			ID:     "idspam",
    67  			Status: payload.StateRunning,
    68  			Labels: []string{"a-tag"},
    69  			Unit:   "a-service/0",
    70  		},
    71  		Machine: "1",
    72  	})
    73  }