@@ -34,29 +34,24 @@ describe('InvokeFunction', () => {
34
34
35
35
describe ( '#invokeFunction()' , ( ) => {
36
36
let invokeStub ;
37
- let getLogsStub ;
38
- let printLogsStub ;
37
+ let printResultStub ;
39
38
40
39
beforeEach ( ( ) => {
41
40
invokeStub = sinon . stub ( googleInvoke , 'invoke' )
42
41
. returns ( BbPromise . resolve ( ) ) ;
43
- getLogsStub = sinon . stub ( googleInvoke , 'getLogs' )
44
- . returns ( BbPromise . resolve ( ) ) ;
45
- printLogsStub = sinon . stub ( googleInvoke , 'printLogs' )
42
+ printResultStub = sinon . stub ( googleInvoke , 'printResult' )
46
43
. returns ( BbPromise . resolve ( ) ) ;
47
44
} ) ;
48
45
49
46
afterEach ( ( ) => {
50
47
googleInvoke . invoke . restore ( ) ;
51
- googleInvoke . getLogs . restore ( ) ;
52
- googleInvoke . printLogs . restore ( ) ;
48
+ googleInvoke . printResult . restore ( ) ;
53
49
} ) ;
54
50
55
51
it ( 'should run promise chain' , ( ) => googleInvoke
56
52
. invokeFunction ( ) . then ( ( ) => {
57
53
expect ( invokeStub . calledOnce ) . toEqual ( true ) ;
58
- expect ( getLogsStub . calledAfter ( invokeStub ) ) ;
59
- expect ( printLogsStub . calledAfter ( getLogsStub ) ) ;
54
+ expect ( printResultStub . calledAfter ( invokeStub ) ) ;
60
55
} ) ) ;
61
56
} ) ;
62
57
@@ -117,44 +112,7 @@ describe('InvokeFunction', () => {
117
112
} ) ;
118
113
} ) ;
119
114
120
- describe ( '#getLogs()' , ( ) => {
121
- let requestStub ;
122
-
123
- beforeEach ( ( ) => {
124
- requestStub = sinon . stub ( googleInvoke . provider , 'request' ) . returns ( BbPromise . resolve ( ) ) ;
125
- } ) ;
126
-
127
- afterEach ( ( ) => {
128
- googleInvoke . provider . request . restore ( ) ;
129
- } ) ;
130
-
131
- it ( 'should return the recent logs of the previously called function' , ( ) => {
132
- googleInvoke . options . function = 'func1' ;
133
-
134
- return googleInvoke . getLogs ( ) . then ( ( ) => {
135
- expect ( requestStub . calledWithExactly (
136
- 'logging' ,
137
- 'entries' ,
138
- 'list' ,
139
- {
140
- filter : 'Function execution foo us-central1' ,
141
- orderBy : 'timestamp desc' ,
142
- resourceNames : [
143
- 'projects/my-project' ,
144
- ] ,
145
- pageSize : 2 ,
146
- } ) ) . toEqual ( true ) ;
147
- } ) ;
148
- } ) ;
149
-
150
- it ( 'should throw an error if the function could not be found in the service' , ( ) => {
151
- googleInvoke . options . function = 'missingFunc' ;
152
-
153
- expect ( ( ) => googleInvoke . getLogs ( ) ) . toThrow ( Error ) ;
154
- } ) ;
155
- } ) ;
156
-
157
- describe ( '#printLogs()' , ( ) => {
115
+ describe ( '#printResult()' , ( ) => {
158
116
let consoleLogStub ;
159
117
160
118
beforeEach ( ( ) => {
@@ -165,37 +123,26 @@ describe('InvokeFunction', () => {
165
123
googleInvoke . serverless . cli . log . restore ( ) ;
166
124
} ) ;
167
125
168
- it ( 'should print the received execution result log on the console' , ( ) => {
169
- const logs = {
170
- entries : [
171
- { timestamp : '1970-01-01 00:00' , textPayload : 'Function execution started' } ,
172
- { timestamp : '1970-01-01 00:01' , textPayload : 'Function result' } ,
173
- ] ,
126
+ it ( 'should print the received execution result on the console' , ( ) => {
127
+ const result = {
128
+ executionId : 'wasdqwerty' ,
129
+ result : 'Foo bar' ,
174
130
} ;
175
131
176
132
const expectedOutput =
177
- '1970-01-01 00:01: Function result ' ;
133
+ 'wasdqwerty: Foo bar ' ;
178
134
179
- return googleInvoke . printLogs ( logs ) . then ( ( ) => {
135
+ return googleInvoke . printResult ( result ) . then ( ( ) => {
180
136
expect ( consoleLogStub . calledWithExactly ( expectedOutput ) ) . toEqual ( true ) ;
181
137
} ) ;
182
138
} ) ;
183
139
184
- it ( 'should print a default message to the console when no logs were received' , ( ) => {
185
- const date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
186
- const logs = {
187
- entries : [
188
- { } ,
189
- {
190
- timestamp : date ,
191
- textPayload : 'There is no log data available right now...' ,
192
- } ,
193
- ] ,
194
- } ;
140
+ it ( 'should print an error message to the console when no result was received' , ( ) => {
141
+ const result = { } ;
195
142
196
- const expectedOutput = ` ${ date } : ${ logs . entries [ 1 ] . textPayload } ` ;
143
+ const expectedOutput = 'error: An error occurred while executing your function...' ;
197
144
198
- return googleInvoke . printLogs ( { } ) . then ( ( ) => {
145
+ return googleInvoke . printResult ( result ) . then ( ( ) => {
199
146
expect ( consoleLogStub . calledWithExactly ( expectedOutput ) ) . toEqual ( true ) ;
200
147
} ) ;
201
148
} ) ;
0 commit comments