[Branch ~go-bot/juju-core/trunk] Rev 1666

Tim Penhey tim.penhey at canonical.com
Thu Aug 15 21:30:11 UTC 2013


Hi folks,

Just wanting to raise awareness of a few testing functions:

+func (s *EndpointSuite) TestEndpoint(c *gc.C) {
+	ctx := coretesting.Context(c)

What is wrong with calling a variable "context"?

+	code := cmd.Main(&EndpointCommand{}, ctx, []string{})
+	c.Check(code, gc.Equals, 0)
+	c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")

c.Assert(coretesting.Stderr(ctx), gc.Equals, "")

+	output := string(ctx.Stdout.(*bytes.Buffer).Bytes())
+	info := s.APIInfo(c)
+	c.Assert(output, gc.Equals, fmt.Sprintf("%s\n", info.Addrs[0]))

expected := fmt.Sprintf("%s\n", info.Addrs[0])
c.Assert(coretesting.Stdout(ctx), gc.Equals, expected)

or

c.Assert(coretesting.Stdout(ctx), gc.Equals, info.Addrs[0] + "\n")

+}

Way back I added the testing methods Stdout and Stderr to avoid having
the bytes.Buffer casts in tests.

Tim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: revision-diff.txt
Type: text/x-diff
Size: 3085 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20130816/c0c0ebeb/attachment.diff>


More information about the Juju-dev mailing list