|
| 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