Beispiel #1
0
func (s *listSuite) TestOkay(c *gc.C) {
	p1 := status.NewPayload("spam", "a-application", 1, 0)
	p1.Labels = []string{"a-tag"}
	p2 := status.NewPayload("eggs", "another-application", 2, 1)
	s.client.payloads = append(s.client.payloads, p1, p2)

	command := status.NewListCommand(s.newAPIClient)
	code, stdout, stderr := runList(c, command)
	c.Assert(code, gc.Equals, 0)

	c.Check(stdout, gc.Equals, `
[Unit Payloads]
Unit                   Machine  Payload class  Status   Type    Id      Tags   
a-application/0        1        spam           running  docker  idspam  a-tag  
another-application/1  2        eggs           running  docker  ideggs         

`[1:])
	c.Check(stderr, gc.Equals, "")
}
Beispiel #2
0
func (s *listSuite) TestOkay(c *gc.C) {
	p1 := status.NewPayload("spam", "a-service", 1, 0)
	p1.Labels = []string{"a-tag"}
	p2 := status.NewPayload("eggs", "another-service", 2, 1)
	s.client.payloads = append(s.client.payloads, p1, p2)

	command := status.NewListCommand(s.newAPIClient)
	code, stdout, stderr := runList(c, command)
	c.Assert(code, gc.Equals, 0)

	c.Check(stdout, gc.Equals, `
[Unit Payloads]
UNIT              MACHINE PAYLOAD-CLASS STATUS  TYPE   ID     TAGS  
a-service/0       1       spam          running docker idspam a-tag 
another-service/1 2       eggs          running docker ideggs       

`[1:])
	c.Check(stderr, gc.Equals, "")
}
Beispiel #3
0
func (s *listSuite) TestPatternsOkay(c *gc.C) {
	p1 := status.NewPayload("spam", "a-application", 1, 0)
	p1.Labels = []string{"a-tag"}
	p2 := status.NewPayload("eggs", "another-application", 2, 1)
	p2.Labels = []string{"a-tag"}
	s.client.payloads = append(s.client.payloads, p1, p2)

	command := status.NewListCommand(s.newAPIClient)
	args := []string{
		"a-tag",
		"other",
		"some-application/1",
	}
	code, stdout, stderr := runList(c, command, args...)
	c.Assert(code, gc.Equals, 0)

	c.Check(stdout, gc.Equals, `
[Unit Payloads]
Unit                   Machine  Payload class  Status   Type    Id      Tags   
a-application/0        1        spam           running  docker  idspam  a-tag  
another-application/1  2        eggs           running  docker  ideggs  a-tag  

`[1:])
	c.Check(stderr, gc.Equals, "")
	s.stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "newAPIClient",
		Args: []interface{}{
			command,
		},
	}, {
		FuncName: "List",
		Args: []interface{}{
			[]string{
				"a-tag",
				"other",
				"some-application/1",
			},
		},
	}, {
		FuncName: "Close",
	}})
}
Beispiel #4
0
func (s *outputTabularSuite) TestFormatTabularMinimal(c *gc.C) {
	payload := status.NewPayload("spam", "a-service", 1, 0)
	formatted := status.Formatted(payload)
	data, err := status.FormatTabular(formatted)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(string(data), gc.Equals, `
[Unit Payloads]
UNIT        MACHINE PAYLOAD-CLASS STATUS  TYPE   ID     TAGS 
a-service/0 1       spam          running docker idspam      
`[1:])
}
Beispiel #5
0
func (s *outputTabularSuite) TestFormatTabularMulti(c *gc.C) {
	p10A := status.NewPayload("spam", "a-service", 1, 0)
	p10A.Labels = []string{"a-tag"}
	p21A := status.NewPayload("spam", "a-service", 2, 1)
	p21A.Status = "stopped"
	p21A.Labels = []string{"a-tag"}
	p21B := status.NewPayload("spam", "a-service", 2, 1)
	p21B.ID += "B"
	p21x := status.NewPayload("eggs", "a-service", 2, 1)
	p21x.Type = "kvm"
	p22A := status.NewPayload("spam", "a-service", 2, 2)
	p10x := status.NewPayload("ham", "another-service", 1, 0)
	p10x.Labels = []string{"other", "extra"}
	formatted := status.Formatted(
		p10A,
		p21A,
		p21B,
		p21x,
		p22A,
		p10x,
	)
	data, err := status.FormatTabular(formatted)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(string(data), gc.Equals, `
[Unit Payloads]
UNIT              MACHINE PAYLOAD-CLASS STATUS  TYPE   ID      TAGS        
a-service/0       1       spam          running docker idspam  a-tag       
a-service/1       2       spam          stopped docker idspam  a-tag       
a-service/1       2       spam          running docker idspamB             
a-service/1       2       eggs          running kvm    ideggs              
a-service/2       2       spam          running docker idspam              
another-service/0 1       ham           running docker idham   other extra 
`[1:])
}
Beispiel #6
0
func (s *outputTabularSuite) TestFormatTabularMinimal(c *gc.C) {
	payload := status.NewPayload("spam", "a-application", 1, 0)
	formatted := status.Formatted(payload)
	buff := &bytes.Buffer{}
	err := status.FormatTabular(buff, formatted)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(buff.String(), gc.Equals, `
[Unit Payloads]
UNIT             MACHINE  PAYLOAD-CLASS  STATUS   TYPE    ID      TAGS  
a-application/0  1        spam           running  docker  idspam        
`[1:])
}
Beispiel #7
0
func (s *outputTabularSuite) TestFormatTabularMinimal(c *gc.C) {
	payload := status.NewPayload("spam", "a-application", 1, 0)
	formatted := status.Formatted(payload)
	buff := &bytes.Buffer{}
	err := status.FormatTabular(buff, formatted)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(buff.String(), gc.Equals, `
[Unit Payloads]
Unit             Machine  Payload class  Status   Type    Id      Tags  
a-application/0  1        spam           running  docker  idspam        
`[1:])
}
Beispiel #8
0
func (s *formatterSuite) TestFormatPayloadOkay(c *gc.C) {
	payload := status.NewPayload("spam", "a-application", 1, 0)
	payload.Labels = []string{"a-tag"}
	formatted := status.FormatPayload(payload)

	c.Check(formatted, jc.DeepEquals, status.FormattedPayload{
		Unit:    "a-application/0",
		Machine: "1",
		ID:      "idspam",
		Type:    "docker",
		Class:   "spam",
		Labels:  []string{"a-tag"},
		Status:  "running",
	})
}
Beispiel #9
0
func (s *outputTabularSuite) TestFormatTabularMulti(c *gc.C) {
	p10A := status.NewPayload("spam", "a-application", 1, 0)
	p10A.Labels = []string{"a-tag"}
	p21A := status.NewPayload("spam", "a-application", 2, 1)
	p21A.Status = "stopped"
	p21A.Labels = []string{"a-tag"}
	p21B := status.NewPayload("spam", "a-application", 2, 1)
	p21B.ID += "B"
	p21x := status.NewPayload("eggs", "a-application", 2, 1)
	p21x.Type = "kvm"
	p22A := status.NewPayload("spam", "a-application", 2, 2)
	p10x := status.NewPayload("ham", "another-application", 1, 0)
	p10x.Labels = []string{"other", "extra"}
	formatted := status.Formatted(
		p10A,
		p21A,
		p21B,
		p21x,
		p22A,
		p10x,
	)
	buff := &bytes.Buffer{}
	err := status.FormatTabular(buff, formatted)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(buff.String(), gc.Equals, `
[Unit Payloads]
Unit                   Machine  Payload class  Status   Type    Id       Tags         
a-application/0        1        spam           running  docker  idspam   a-tag        
a-application/1        2        spam           stopped  docker  idspam   a-tag        
a-application/1        2        spam           running  docker  idspamB               
a-application/1        2        eggs           running  kvm     ideggs                
a-application/2        2        spam           running  docker  idspam                
another-application/0  1        ham            running  docker  idham    other extra  
`[1:])
}
Beispiel #10
0
func (s *listSuite) TestOutputFormats(c *gc.C) {
	p1 := status.NewPayload("spam", "a-application", 1, 0)
	p1.Labels = []string{"a-tag"}
	p2 := status.NewPayload("eggs", "another-application", 2, 1)
	s.client.payloads = append(s.client.payloads,
		p1,
		p2,
	)

	formats := map[string]string{
		"tabular": `
[Unit Payloads]
Unit                   Machine  Payload class  Status   Type    Id      Tags   
a-application/0        1        spam           running  docker  idspam  a-tag  
another-application/1  2        eggs           running  docker  ideggs         

`[1:],
		"yaml": `
- unit: a-application/0
  machine: "1"
  id: idspam
  type: docker
  payload-class: spam
  tags:
  - a-tag
  status: running
- unit: another-application/1
  machine: "2"
  id: ideggs
  type: docker
  payload-class: eggs
  status: running
`[1:],
		"json": strings.Replace(""+
			"["+
			" {"+
			`  "unit":"a-application/0",`+
			`  "machine":"1",`+
			`  "id":"idspam",`+
			`  "type":"docker",`+
			`  "payload-class":"spam",`+
			`  "tags":["a-tag"],`+
			`  "status":"running"`+
			" },{"+
			`  "unit":"another-application/1",`+
			`  "machine":"2",`+
			`  "id":"ideggs",`+
			`  "type":"docker",`+
			`  "payload-class":"eggs",`+
			`  "status":"running"`+
			" }"+
			"]\n",
			" ", "", -1),
	}
	for format, expected := range formats {
		command := status.NewListCommand(s.newAPIClient)
		args := []string{
			"--format", format,
		}
		code, stdout, stderr := runList(c, command, args...)
		c.Assert(code, gc.Equals, 0)

		c.Check(stdout, gc.Equals, expected)
		c.Check(stderr, gc.Equals, "")
	}
}