github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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 "bytes" 8 9 "github.com/juju/testing" 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/payload/status" 14 ) 15 16 var _ = gc.Suite(&outputTabularSuite{}) 17 18 type outputTabularSuite struct { 19 testing.IsolationSuite 20 } 21 22 func (s *outputTabularSuite) TestFormatTabularOkay(c *gc.C) { 23 payload := status.NewPayload("spam", "a-application", 1, 0) 24 payload.Labels = []string{"a-tag", "other"} 25 formatted := status.Formatted(payload) 26 buff := &bytes.Buffer{} 27 err := status.FormatTabular(buff, formatted) 28 c.Assert(err, jc.ErrorIsNil) 29 30 c.Check(buff.String(), gc.Equals, ` 31 [Unit Payloads] 32 Unit Machine Payload class Status Type Id Tags 33 a-application/0 1 spam running docker idspam a-tag other 34 `[1:]) 35 } 36 37 func (s *outputTabularSuite) TestFormatTabularMinimal(c *gc.C) { 38 payload := status.NewPayload("spam", "a-application", 1, 0) 39 formatted := status.Formatted(payload) 40 buff := &bytes.Buffer{} 41 err := status.FormatTabular(buff, formatted) 42 c.Assert(err, jc.ErrorIsNil) 43 44 c.Check(buff.String(), gc.Equals, ` 45 [Unit Payloads] 46 Unit Machine Payload class Status Type Id Tags 47 a-application/0 1 spam running docker idspam 48 `[1:]) 49 } 50 51 func (s *outputTabularSuite) TestFormatTabularMulti(c *gc.C) { 52 p10A := status.NewPayload("spam", "a-application", 1, 0) 53 p10A.Labels = []string{"a-tag"} 54 p21A := status.NewPayload("spam", "a-application", 2, 1) 55 p21A.Status = "stopped" 56 p21A.Labels = []string{"a-tag"} 57 p21B := status.NewPayload("spam", "a-application", 2, 1) 58 p21B.ID += "B" 59 p21x := status.NewPayload("eggs", "a-application", 2, 1) 60 p21x.Type = "kvm" 61 p22A := status.NewPayload("spam", "a-application", 2, 2) 62 p10x := status.NewPayload("ham", "another-application", 1, 0) 63 p10x.Labels = []string{"other", "extra"} 64 formatted := status.Formatted( 65 p10A, 66 p21A, 67 p21B, 68 p21x, 69 p22A, 70 p10x, 71 ) 72 buff := &bytes.Buffer{} 73 err := status.FormatTabular(buff, formatted) 74 c.Assert(err, jc.ErrorIsNil) 75 76 c.Check(buff.String(), gc.Equals, ` 77 [Unit Payloads] 78 Unit Machine Payload class Status Type Id Tags 79 a-application/0 1 spam running docker idspam a-tag 80 a-application/1 2 spam stopped docker idspam a-tag 81 a-application/1 2 spam running docker idspamB 82 a-application/1 2 eggs running kvm ideggs 83 a-application/2 2 spam running docker idspam 84 another-application/0 1 ham running docker idham other extra 85 `[1:]) 86 } 87 88 func (s *outputTabularSuite) TestFormatTabularBadValue(c *gc.C) { 89 bogus := "should have been []formattedPayload" 90 err := status.FormatTabular(nil, bogus) 91 c.Check(err, gc.ErrorMatches, `expected value of type .*`) 92 }