| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package cloudlog | |
| 6 | |
| 7 import ( | |
| 8 "testing" | |
| 9 "time" | |
| 10 | |
| 11 "github.com/luci/luci-go/common/clock/testclock" | |
| 12 "github.com/luci/luci-go/common/cloudlogging" | |
| 13 "github.com/luci/luci-go/common/logging" | |
| 14 . "github.com/smartystreets/goconvey/convey" | |
| 15 "golang.org/x/net/context" | |
| 16 ) | |
| 17 | |
| 18 type testClient struct { | |
| 19 logC chan []*cloudlogging.Entry | |
| 20 err error | |
| 21 } | |
| 22 | |
| 23 func (c *testClient) PushEntries(entries []*cloudlogging.Entry) error { | |
| 24 c.logC <- entries | |
| 25 return c.err | |
| 26 } | |
| 27 | |
| 28 func TestCloudLogging(t *testing.T) { | |
| 29 Convey(`A cloud logging instance using a test client`, t, func() { | |
| 30 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) | |
| 31 ctx, _ := testclock.UseTime(context.Background(), now) | |
| 32 | |
| 33 client := &testClient{ | |
| 34 logC: make(chan []*cloudlogging.Entry, 1), | |
| 35 } | |
| 36 | |
| 37 config := Config{ | |
| 38 InsertIDBase: "totally-random", | |
| 39 } | |
| 40 | |
| 41 ctx = Use(ctx, config, client) | |
| 42 | |
| 43 Convey(`Can publish logging data.`, func() { | |
| 44 logging.Fields{ | |
| 45 "foo": "bar", | |
| 46 }.Infof(ctx, "Message at %s", "INFO") | |
| 47 | |
| 48 entries := <-client.logC | |
| 49 So(len(entries), ShouldEqual, 1) | |
| 50 So(entries[0], ShouldResemble, &cloudlogging.Entry{ | |
| 51 InsertID: "totally-random.0.0", | |
| 52 Timestamp: now, | |
| 53 Severity: cloudlogging.Info, | |
| 54 Labels: cloudlogging.Labels{ | |
| 55 "foo": "bar", | |
| 56 }, | |
| 57 TextPayload: `Message at INFO {"foo":"bar"}`, | |
| 58 }) | |
| 59 }) | |
| 60 }) | |
| 61 } | |
| OLD | NEW |