Exemple #1
0
func (s *listSuite) TestNoPayloads(c *gc.C) {
	command := status.NewListCommand(s.newAPIClient)
	code, stdout, stderr := runList(c, command)
	c.Assert(code, gc.Equals, 0)

	c.Check(stderr, gc.Equals, "No payloads to display.\n")
	c.Check(stdout, gc.Equals, "")
}
Exemple #2
0
func (c payloads) registerPublicCommands() {
	if !markRegistered(payload.ComponentName, "public-commands") {
		return
	}

	commands.RegisterEnvCommand(func() envcmd.EnvironCommand {
		return status.NewListCommand(c.newListAPIClient)
	})
}
Exemple #3
0
func (s *listSuite) TestNoPayloads(c *gc.C) {
	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 

`[1:])
	c.Check(stderr, gc.Equals, "")
}
Exemple #4
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, "")
}
Exemple #5
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, "")
}
Exemple #6
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",
	}})
}
Exemple #7
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, "")
	}
}