func assertLogs(c *gc.C, ctx jujuc.Context, writer *loggo.TestWriter, unitname, badge string) { msg1 := "the chickens" msg2 := "are 110% AWESOME" com, err := jujuc.NewCommand(ctx, cmdString("juju-log")) c.Assert(err, jc.ErrorIsNil) for _, t := range []struct { args []string level loggo.Level }{ { level: loggo.INFO, }, { args: []string{"--debug"}, level: loggo.DEBUG, }, { args: []string{"--log-level", "TRACE"}, level: loggo.TRACE, }, { args: []string{"--log-level", "info"}, level: loggo.INFO, }, { args: []string{"--log-level", "WaRnInG"}, level: loggo.WARNING, }, { args: []string{"--log-level", "error"}, level: loggo.ERROR, }, } { writer.Clear() c.Assert(err, jc.ErrorIsNil) args := append(t.args, msg1, msg2) code := cmd.Main(com, &cmd.Context{}, args) c.Assert(code, gc.Equals, 0) log := writer.Log() c.Assert(log, gc.HasLen, 1) c.Assert(log[0].Level, gc.Equals, t.level) c.Assert(log[0].Module, gc.Equals, fmt.Sprintf("unit.%s.juju-log", unitname)) c.Assert(log[0].Message, gc.Equals, fmt.Sprintf("%s%s %s", badge, msg1, msg2)) } }
func checkLastMessage(c *gc.C, writer *loggo.TestWriter, expected string) { log := writer.Log() writer.Clear() obtained := log[len(log)-1].Message c.Check(obtained, gc.Equals, expected) }