本文整理匯總了Golang中github.com/juju/loggo.TestWriter.Clear方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestWriter.Clear方法的具體用法?Golang TestWriter.Clear怎麽用?Golang TestWriter.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/loggo.TestWriter
的用法示例。
在下文中一共展示了TestWriter.Clear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assertLogs
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))
}
}
示例2: checkLastMessage
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)
}