Skip to content

Commit 568fec4

Browse files
add constructor test
1 parent 21072be commit 568fec4

3 files changed

Lines changed: 135 additions & 255 deletions

File tree

packages/logging-winston/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"async": "^2.1.4",
37+
"extend": "^3.0.0",
3738
"mocha": "^2.5.3"
3839
},
3940
"scripts": {
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 extend = require('extend');
21+
var proxyquire = require('proxyquire');
22+
23+
describe('logging-winston', function() {
24+
var fakeLogInstance = {};
25+
26+
var fakeLoggingOptions_;
27+
var fakeLogName_;
28+
29+
function fakeLogging(options) {
30+
fakeLoggingOptions_ = options;
31+
return {
32+
log: function(logName) {
33+
fakeLogName_ = logName;
34+
return fakeLogInstance;
35+
}
36+
};
37+
}
38+
39+
function FakeTransport() {
40+
this.transportCalledWith_ = arguments;
41+
}
42+
43+
var fakeWinston = {
44+
transports: {},
45+
Transport: FakeTransport
46+
};
47+
48+
var LoggingWinston;
49+
var loggingWinston;
50+
51+
var OPTIONS = {
52+
level: 'level',
53+
levels: [1, 2, 3],
54+
logName: 'log-name',
55+
resource: {}
56+
};
57+
58+
before(function() {
59+
LoggingWinston = proxyquire('../src/index.js', {
60+
'@google-cloud/logging': fakeLogging,
61+
winston: fakeWinston
62+
});
63+
});
64+
65+
beforeEach(function() {
66+
fakeLoggingOptions_ = null;
67+
fakeLogName_ = null;
68+
loggingWinston = new LoggingWinston(OPTIONS);
69+
});
70+
71+
describe('instantiation', function() {
72+
it('should create a new instance of LoggingWinston', function() {
73+
// jshint newcap:false
74+
var loggingWinston = LoggingWinston(OPTIONS);
75+
assert(loggingWinston instanceof LoggingWinston);
76+
});
77+
78+
it('should inherit from winston.Transport', function() {
79+
assert.deepEqual(loggingWinston.transportCalledWith_[0], {
80+
level: OPTIONS.level,
81+
name: OPTIONS.logName
82+
});
83+
});
84+
85+
it('should assign itself to winston.transports', function() {
86+
assert.strictEqual(
87+
fakeWinston.transports.StackdriverLogging,
88+
LoggingWinston
89+
);
90+
});
91+
92+
it('should localize provided levels', function() {
93+
assert.strictEqual(loggingWinston.levels_, OPTIONS.levels);
94+
});
95+
96+
it('should default to npm levels', function() {
97+
var optionsWithoutLevels = extend({}, OPTIONS);
98+
delete optionsWithoutLevels.levels;
99+
100+
var loggingWinston = new LoggingWinston(optionsWithoutLevels);
101+
assert.deepEqual(loggingWinston.levels_, {
102+
error: 3,
103+
warn: 4,
104+
info: 6,
105+
verbose: 7,
106+
debug: 7,
107+
silly: 7
108+
});
109+
});
110+
111+
it('should localize Log instance using provided name', function() {
112+
var logName = 'log-name-override';
113+
114+
var optionsWithLogName = extend({}, OPTIONS);
115+
optionsWithLogName.logName = logName;
116+
117+
new LoggingWinston(optionsWithLogName);
118+
119+
assert.strictEqual(fakeLoggingOptions_, optionsWithLogName);
120+
assert.strictEqual(fakeLogName_, logName);
121+
});
122+
123+
it('should localize Log instance using default name', function() {
124+
assert.strictEqual(fakeLoggingOptions_, OPTIONS);
125+
assert.strictEqual(fakeLogName_, OPTIONS.logName);
126+
});
127+
128+
it('should localize the provided resource', function() {
129+
assert.strictEqual(loggingWinston.resource_, OPTIONS.resource);
130+
});
131+
});
132+
133+
describe('log', function() {});
134+
});

packages/logging-winston/test/test-winston.js

Lines changed: 0 additions & 255 deletions
This file was deleted.

0 commit comments

Comments
 (0)