| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package memlogger | |
| 6 | |
| 7 import ( | |
| 8 "testing" | |
| 9 | |
| 10 "golang.org/x/net/context" | |
| 11 | |
| 12 . "github.com/smartystreets/goconvey/convey" | |
| 13 | |
| 14 "infra/libs/logging" | |
| 15 ) | |
| 16 | |
| 17 func TestLogger(t *testing.T) { | |
| 18 Convey("logger", t, func() { | |
| 19 c := Use(context.Background()) | |
| 20 l := logging.Get(c) | |
| 21 So(l, ShouldNotBeNil) | |
| 22 l.Infof("test %s", LogInfo) | |
| 23 l.Warningf("test %s", LogWarn) | |
| 24 l.Errorf("test %s", LogError) | |
| 25 l.Errorf("test WAT: %s", LogLevel(9001)) | |
| 26 ml := l.(*MemLogger) | |
| 27 | |
| 28 So(len(*ml), ShouldEqual, 4) | |
| 29 So((*ml)[0], ShouldResemble, LogEntry{LogInfo, "test IFO"}) | |
| 30 So((*ml)[1], ShouldResemble, LogEntry{LogWarn, "test WRN"}) | |
| 31 So((*ml)[2], ShouldResemble, LogEntry{LogError, "test ERR"}) | |
| 32 So((*ml)[3], ShouldResemble, LogEntry{LogError, "test WAT: ???"}
) | |
| 33 }) | |
| 34 | |
| 35 Convey("logger context", t, func() { | |
| 36 c := Use(context.Background()) | |
| 37 l := logging.Get(c) | |
| 38 So(l, ShouldNotBeNil) | |
| 39 ml := l.(*MemLogger) | |
| 40 | |
| 41 l.Infof("totally works: %s", "yes") | |
| 42 | |
| 43 So(len(*ml), ShouldEqual, 1) | |
| 44 So((*ml)[0], ShouldResemble, LogEntry{LogInfo, "totally works: y
es"}) | |
| 45 }) | |
| 46 } | |
| OLD | NEW |