@@ -15,8 +15,8 @@ require('chai').use(chaiAsPromised);
15
15
describe ( 'OpenWhiskLogs' , ( ) => {
16
16
let sandbox ;
17
17
18
- const CLI = function ( ) { this . log = function ( ) { } ; } ;
19
- const serverless = { config : ( ) => { } , pluginManager : { getPlugins : ( ) => [ ] } , classes : { Error, CLI } , service : { getFunction : ( ) => ( { } ) , provider : { } , resources : { } , getAllFunctions : ( ) => [ ] } , getProvider : sinon . spy ( ) } ;
18
+ const CLI = function ( ) { this . log = function ( ) { } ; } ;
19
+ const serverless = { config : ( ) => { } , pluginManager : { getPlugins : ( ) => [ ] } , classes : { Error, CLI } , service : { getFunction : name => ( serverless . service . functions [ name ] ) , provider : { } , resources : { } , getAllFunctions : ( ) => [ ] } , getProvider : sinon . spy ( ) } ;
20
20
const options = {
21
21
stage : 'dev' ,
22
22
region : 'us-east-1' ,
@@ -64,7 +64,6 @@ describe('OpenWhiskLogs', () => {
64
64
beforeEach ( ( ) => {
65
65
openwhiskLogs . serverless . service . functions = {
66
66
first : {
67
- namespace : 'sample' ,
68
67
handler : true ,
69
68
} ,
70
69
} ;
@@ -110,7 +109,6 @@ describe('OpenWhiskLogs', () => {
110
109
beforeEach ( ( ) => {
111
110
openwhiskLogs . serverless . service . functions = {
112
111
first : {
113
- namespace : 'sample' ,
114
112
handler : true ,
115
113
} ,
116
114
} ;
@@ -153,7 +151,6 @@ describe('OpenWhiskLogs', () => {
153
151
beforeEach ( ( ) => {
154
152
openwhiskLogs . serverless . service . functions = {
155
153
first : {
156
- namespace : 'sample' ,
157
154
handler : true ,
158
155
} ,
159
156
} ;
@@ -165,16 +162,39 @@ describe('OpenWhiskLogs', () => {
165
162
} ) ;
166
163
167
164
it ( 'should filter out different function logs' , ( ) => {
168
- const logs = [ { name : "new-service_first" } , { name : "new-service_first" } , { name : "new-service_second" } , { name : "new-service_third" } , { name : "new-service_first" } ]
165
+ const logs = [
166
+ { name :
"new-service_first" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] } ,
167
+ { name :
"new-service_first" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] } ,
168
+ { name :
"new-service_second" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_second' } ] } ,
169
+ { name :
"new-service_third" , annotations :
[ { key :
"path" , value :
"[email protected] _dev/new-second_third" } ] } ,
170
+ { name :
"new-service_first" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] }
171
+ ]
169
172
return openwhiskLogs . filterFunctionLogs ( logs ) . then ( logs => {
170
173
expect ( logs . length ) . to . be . equal ( 3 )
171
174
logs . forEach ( log => expect ( log . name ) . to . be . equal ( 'new-service_first' ) )
172
175
} )
173
176
} ) ;
174
177
178
+ it ( 'should filter out different function logs with package function' , ( ) => {
179
+ openwhiskLogs . serverless . service . functions . first . name = 'packagename/funcname'
180
+ const logs = [
181
+ { name :
"funcname" , annotations :
[ { key :
"path" , value :
"[email protected] _dev/packagename/funcname" } ] } ,
182
+ { name :
"funcname" , annotations :
[ { key :
"path" , value :
"[email protected] _dev/packagename/funcname" } ] } ,
183
+ { name :
"new-service_second" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_second' } ] } ,
184
+ { name :
"new-service_third" , annotations :
[ { key :
"path" , value :
"[email protected] _dev/new-second_third" } ] } ,
185
+ { name :
"funcname" , annotations :
[ { key :
"path" , value :
"[email protected] _dev/packagename/funcname" } ] }
186
+ ]
187
+
188
+ return openwhiskLogs . filterFunctionLogs ( logs ) . then ( logs => {
189
+ expect ( logs . length ) . to . be . equal ( 3 )
190
+ logs . forEach ( log => expect ( log . name ) . to . be . equal ( 'funcname' ) )
191
+ } )
192
+ } ) ;
193
+
194
+
175
195
it ( 'should filter out logs lines based upon contents' , ( ) => {
176
196
openwhiskLogs . options . startTime = moment ( '2001-01-01' )
177
- const logs = [ { name : "new-service_first" , logs : [ "2001-01-02 matching line" , "2001-01-01 another matching line" , "2000-12-31 should not match" ] } ]
197
+ const logs = [ { name :
"new-service_first" , annotations : [ { key : "path" , value : '[email protected] _dev/new-service_first' } ] , logs :
[ "2001-01-02 matching line" , "2001-01-01 another matching line" , "2000-12-31 should not match" ] } ]
178
198
return openwhiskLogs . filterFunctionLogs ( logs ) . then ( logs => {
179
199
expect ( logs . length ) . to . be . equal ( 1 )
180
200
expect ( logs [ 0 ] . logs ) . to . be . deep . equal ( [ "2001-01-02 matching line" ] )
@@ -184,7 +204,11 @@ describe('OpenWhiskLogs', () => {
184
204
185
205
it ( 'should filter out logs lines based upon contents' , ( ) => {
186
206
openwhiskLogs . options . filter = new RegExp ( 'matching' , 'i' )
187
- const logs = [ { name : "new-service_first" , logs : [ "matching line" , "another matching line" , "should not match" ] } , { name : "new-service_first" , logs : [ "does not match" ] } ]
207
+ const logs = [
208
+ { name :
"new-service_first" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] , logs :
[ "matching line" , "another matching line" , "should not match" ] } ,
209
+ { name :
"new-service_first" , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] , logs :
[ "does not match" ] }
210
+ ]
211
+
188
212
return openwhiskLogs . filterFunctionLogs ( logs ) . then ( logs => {
189
213
expect ( logs . length ) . to . be . equal ( 2 )
190
214
expect ( logs [ 0 ] . logs ) . to . be . deep . equal ( [ "matching line" , "another matching line" ] )
@@ -193,11 +217,14 @@ describe('OpenWhiskLogs', () => {
193
217
} )
194
218
} ) ;
195
219
196
-
197
-
198
220
it ( 'should filter already seen log messages' , ( ) => {
199
221
openwhiskLogs . previous_activations = new Set ( [ 1 , 2 , 3 , 4 , 5 ] )
200
- const logs = [ { activationId : 1 , name : "new-service_first" } , { activationId : 5 , name : "new-service_first" } , { activationId : 6 , name : "new-service_first" } ]
222
+ const logs = [
223
+ { activationId :
1 , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] , name :
"new-service_first" } ,
224
+ { activationId :
5 , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] , name :
"new-service_first" } ,
225
+ { activationId :
6 , annotations :
[ { key :
"path" , value :
'[email protected] _dev/new-service_first' } ] , name :
"new-service_first" }
226
+ ]
227
+
201
228
return openwhiskLogs . filterFunctionLogs ( logs ) . then ( logs => {
202
229
expect ( logs . length ) . to . be . equal ( 1 )
203
230
expect ( logs [ 0 ] . name ) . to . be . equal ( 'new-service_first' )
@@ -211,7 +238,6 @@ describe('OpenWhiskLogs', () => {
211
238
beforeEach ( ( ) => {
212
239
openwhiskLogs . serverless . service . functions = {
213
240
first : {
214
- namespace : 'sample' ,
215
241
handler : true ,
216
242
} ,
217
243
} ;
0 commit comments