Skip to content

Commit 46b858d

Browse files
committed
logging-winston: add system tests
1 parent f7aedb8 commit 46b858d

2 files changed

Lines changed: 81 additions & 3 deletions

File tree

packages/logging-winston/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ var levelNames = Object.keys(levels);
8686
/**
8787
* @typedef {object} OptionsObject
8888
* @property {string=} logName - The name of the log that will receive
89-
* messages written to this stream (default: 'winston_log').
89+
* messages written to this transport (default: 'winston_log').
9090
* @property {object=} levels - Custom logging levels as supported by winston.
9191
* We use this list of levels to translate your log level to the Stackdriver
9292
* Logging level. Each property should have an integer value between 0 (most
9393
* severe) and 7 (least severe). If you are passing a list of levels to your
9494
* winston logger, you should provide the same list here.
9595
* @property {object=} level - Default log level for the transport. Winston
9696
* will filter messages with a severity lower than this.
97-
* @property {object=} resource - The monitored resource that the stream
97+
* @property {object=} resource - The monitored resource that the transport
9898
* corresponds to. On Google Cloud Platform we infer this automatically, but
9999
* you may optionally specify a specific monitored resource. For more
100100
* information see the [official documentation]{@link
@@ -121,7 +121,7 @@ var levelNames = Object.keys(levels);
121121
*/
122122

123123
/**
124-
* Constructs a new object which can be used as a Winston stream.
124+
* Constructs a new object which can be used as a Winston transport.
125125
* @param {OptionsObject=} options - optional configuration object.
126126
* @constructor
127127
*/
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*!
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var assert = require('assert');
20+
var env = require('../../../system-test/env.js');
21+
var winston = require('winston');
22+
var StackdriverTransport = require('../');
23+
var util = require('util');
24+
25+
describe('Logging-winston', function() {
26+
var WRITE_CONSISTENCY_DELAY_MS = 20000;
27+
28+
var transport = new StackdriverTransport(env);
29+
var logger = new winston.Logger({transports: [transport]});
30+
31+
32+
describe('log', function() {
33+
34+
var testData = [
35+
{
36+
args: ['first'],
37+
verify: function(entry) { assert.strictEqual(entry.data, 'first'); }
38+
},
39+
40+
{
41+
args: ['second'],
42+
verify: function(entry) { assert.strictEqual(entry.data, 'second'); }
43+
},
44+
45+
{
46+
args: ['third', {test_timestamp: new Date(5)}],
47+
verify: function(entry) {
48+
assert.strictEqual(entry.data, 'third');
49+
assert.ok(entry.metadata && entry.metadata.labels);
50+
}
51+
}
52+
53+
];
54+
55+
it('should properly write log entries to the service', function(done) {
56+
testData.forEach(function(test) {
57+
logger.info.apply(logger, test.args);
58+
});
59+
60+
setTimeout(function() {
61+
transport.logger_.getEntries(
62+
{pageSize: testData.length}, function(err, entries) {
63+
assert.ifError(err);
64+
assert.strictEqual(entries.length, testData.length);
65+
66+
entries.reverse();
67+
68+
entries.forEach(function(entry, index) {
69+
var test = testData[index];
70+
test.verify(entry);
71+
});
72+
done();
73+
});
74+
}, WRITE_CONSISTENCY_DELAY_MS);
75+
});
76+
77+
});
78+
});

0 commit comments

Comments
 (0)