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

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package status_test
     5  
     6  import (
     7  	"github.com/juju/testing"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/payload/status"
    12  )
    13  
    14  var _ = gc.Suite(&outputTabularSuite{})
    15  
    16  type outputTabularSuite struct {
    17  	testing.IsolationSuite
    18  }
    19  
    20  func (s *outputTabularSuite) TestFormatTabularOkay(c *gc.C) {
    21  	payload := status.NewPayload("spam", "a-service", 1, 0)
    22  	payload.Labels = []string{"a-tag", "other"}
    23  	formatted := status.Formatted(payload)
    24  	data, err := status.FormatTabular(formatted)
    25  	c.Assert(err, jc.ErrorIsNil)
    26  
    27  	c.Check(string(data), gc.Equals, `
    28  [Unit Payloads]
    29  UNIT        MACHINE PAYLOAD-CLASS STATUS  TYPE   ID     TAGS        
    30  a-service/0 1       spam          running docker idspam a-tag other 
    31  `[1:])
    32  }
    33  
    34  func (s *outputTabularSuite) TestFormatTabularMinimal(c *gc.C) {
    35  	payload := status.NewPayload("spam", "a-service", 1, 0)
    36  	formatted := status.Formatted(payload)
    37  	data, err := status.FormatTabular(formatted)
    38  	c.Assert(err, jc.ErrorIsNil)
    39  
    40  	c.Check(string(data), gc.Equals, `
    41  [Unit Payloads]
    42  UNIT        MACHINE PAYLOAD-CLASS STATUS  TYPE   ID     TAGS 
    43  a-service/0 1       spam          running docker idspam      
    44  `[1:])
    45  }
    46  
    47  func (s *outputTabularSuite) TestFormatTabularMulti(c *gc.C) {
    48  	p10A := status.NewPayload("spam", "a-service", 1, 0)
    49  	p10A.Labels = []string{"a-tag"}
    50  	p21A := status.NewPayload("spam", "a-service", 2, 1)
    51  	p21A.Status = "stopped"
    52  	p21A.Labels = []string{"a-tag"}
    53  	p21B := status.NewPayload("spam", "a-service", 2, 1)
    54  	p21B.ID += "B"
    55  	p21x := status.NewPayload("eggs", "a-service", 2, 1)
    56  	p21x.Type = "kvm"
    57  	p22A := status.NewPayload("spam", "a-service", 2, 2)
    58  	p10x := status.NewPayload("ham", "another-service", 1, 0)
    59  	p10x.Labels = []string{"other", "extra"}
    60  	formatted := status.Formatted(
    61  		p10A,
    62  		p21A,
    63  		p21B,
    64  		p21x,
    65  		p22A,
    66  		p10x,
    67  	)
    68  	data, err := status.FormatTabular(formatted)
    69  	c.Assert(err, jc.ErrorIsNil)
    70  
    71  	c.Check(string(data), gc.Equals, `
    72  [Unit Payloads]
    73  UNIT              MACHINE PAYLOAD-CLASS STATUS  TYPE   ID      TAGS        
    74  a-service/0       1       spam          running docker idspam  a-tag       
    75  a-service/1       2       spam          stopped docker idspam  a-tag       
    76  a-service/1       2       spam          running docker idspamB             
    77  a-service/1       2       eggs          running kvm    ideggs              
    78  a-service/2       2       spam          running docker idspam              
    79  another-service/0 1       ham           running docker idham   other extra 
    80  `[1:])
    81  }
    82  
    83  func (s *outputTabularSuite) TestFormatTabularBadValue(c *gc.C) {
    84  	bogus := "should have been []formattedPayload"
    85  	_, err := status.FormatTabular(bogus)
    86  
    87  	c.Check(err, gc.ErrorMatches, `expected value of type .*`)
    88  }