6
. "launchpad.net/gocheck"
7
"launchpad.net/juju-core/cmd"
8
"launchpad.net/juju-core/log"
9
"launchpad.net/juju-core/testing"
10
"launchpad.net/juju-core/worker/uniter/jujuc"
14
type JujuLogSuite struct {
18
var _ = Suite(&JujuLogSuite{})
20
func pushLog(debug bool) (*bytes.Buffer, func()) {
21
oldTarget, oldDebug := log.Target(), log.Debug
23
log.SetTarget(stdlog.New(&buf, "JUJU:", 0))
26
log.SetTarget(oldTarget)
31
var commonLogTests = []struct {
36
{false, false, "JUJU:INFO"},
38
{true, false, "JUJU:INFO"},
39
{true, true, "JUJU:DEBUG"},
42
func assertLogs(c *C, ctx jujuc.Context, badge string) {
43
msg1 := "the chickens"
44
msg2 := "are 110% AWESOME"
45
com, err := jujuc.NewCommand(ctx, "juju-log")
47
for _, t := range commonLogTests {
48
buf, pop := pushLog(t.debugEnabled)
53
args = []string{"--debug", msg1, msg2}
55
args = []string{msg1, msg2}
57
code := cmd.Main(com, &cmd.Context{}, args)
58
c.Assert(code, Equals, 0)
61
c.Assert(buf.String(), Equals, "")
63
expect := fmt.Sprintf("%s %s: %s %s\n", t.target, badge, msg1, msg2)
64
c.Assert(buf.String(), Equals, expect)
69
func (s *JujuLogSuite) TestBadges(c *C) {
70
hctx := s.GetHookContext(c, -1, "")
71
assertLogs(c, hctx, "u/0")
72
hctx = s.GetHookContext(c, 1, "u/1")
73
assertLogs(c, hctx, "u/0 peer1:1")
76
func newJujuLogCommand(c *C) cmd.Command {
78
com, err := jujuc.NewCommand(ctx, "juju-log")
83
func (s *JujuLogSuite) TestRequiresMessage(c *C) {
84
com := newJujuLogCommand(c)
85
testing.TestInit(c, com, nil, "no message specified")
88
func (s *JujuLogSuite) TestLogInitMissingLevel(c *C) {
89
com := newJujuLogCommand(c)
90
testing.TestInit(c, com, []string{"-l"}, "flag needs an argument.*")
93
func (s *JujuLogSuite) TestLogInitMissingMessage(c *C) {
94
com := newJujuLogCommand(c)
95
testing.TestInit(c, com, []string{"-l", "FATAL"}, "no message specified")
98
func (s *JujuLogSuite) TestLogDeprecation(c *C) {
99
com := newJujuLogCommand(c)
100
ctx, err := testing.RunCommand(c, com, []string{"--format", "foo", "msg"})
102
c.Assert(testing.Stderr(ctx), Equals, "--format flag deprecated for command \"juju-log\"")