Exemple #1
0
func (s *StatusSuite) runTestCase(c *gc.C, tc statusTestCase) {
	fakeClient := makeFakeClient(
		0*time.Second, // No API delay
		5*time.Second, // 5 second test timeout
		tc.tags,
		tc.results,
		"", // No API error
	)

	restore := s.patchAPIClient(fakeClient)
	defer restore()

	s.subcommand = &action.StatusCommand{}
	ctx, err := testing.RunCommand(c, s.subcommand, tc.args...)
	if tc.expectError == "" {
		c.Check(err, jc.ErrorIsNil)
	} else {
		c.Check(err, gc.ErrorMatches, tc.expectError)
	}
	if len(tc.results) > 0 {
		buf, err := cmd.DefaultFormatters["yaml"](action.ActionResultsToMap(tc.results))
		c.Check(err, jc.ErrorIsNil)
		c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, string(buf)+"\n")
		c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
	}
}
Exemple #2
0
func (s *StatusSuite) runTestCase(c *gc.C, tc statusTestCase) {
	for _, modelFlag := range s.modelFlags {
		fakeClient := makeFakeClient(
			0*time.Second, // No API delay
			5*time.Second, // 5 second test timeout
			tc.tags,
			tc.results,
			tc.actionsByNames,
			"", // No API error
		)

		restore := s.patchAPIClient(fakeClient)
		defer restore()

		s.subcommand, _ = action.NewStatusCommandForTest(s.store)
		args := append([]string{modelFlag, "admin"}, tc.args...)
		ctx, err := testing.RunCommand(c, s.subcommand, args...)
		if tc.expectError == "" {
			c.Assert(err, jc.ErrorIsNil)
		} else {
			c.Assert(err, gc.ErrorMatches, tc.expectError)
		}
		if len(tc.results) > 0 {
			buf, err := cmd.DefaultFormatters["yaml"](action.ActionResultsToMap(tc.results))
			c.Check(err, jc.ErrorIsNil)
			c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, string(buf)+"\n")
			c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
		}
	}
}