@@ -2,7 +2,7 @@ import { expect } from "chai";
2
2
3
3
import * as runv2 from "./runv2" ;
4
4
import * as backend from "../deploy/functions/backend" ;
5
- import { latest , Runtime } from "../deploy/functions/runtimes/supported" ;
5
+ import { latest } from "../deploy/functions/runtimes/supported" ;
6
6
import { CODEBASE_LABEL } from "../functions/constants" ;
7
7
8
8
describe ( "runv2" , ( ) => {
@@ -23,44 +23,7 @@ describe("runv2", () => {
23
23
cpu : 1 ,
24
24
} ;
25
25
26
- const RUN_SERVICE_V2_OUTPUT_BASE : runv2 . Service = {
27
- name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
28
- generation : 1 ,
29
- labels : {
30
- [ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
31
- [ runv2 . CLIENT_NAME_LABEL ] : "firebase-functions" ,
32
- } ,
33
- annotations : {
34
- [ runv2 . CLIENT_NAME_ANNOTATION ] : "cli-firebase" ,
35
- [ runv2 . FUNCTION_TARGET_ANNOTATION ] : FUNCTION_ID ,
36
- [ runv2 . FUNCTION_ID_ANNOTATION ] : FUNCTION_ID ,
37
- [ runv2 . CPU_BOOST_ANNOTATION ] : "true" ,
38
- } ,
39
- template : {
40
- containers : [
41
- {
42
- name : runv2 . DEFAULT_FUNCTION_CONTAINER_NAME ,
43
- image : IMAGE_URI ,
44
- env : [ ] ,
45
- resources : {
46
- limits : {
47
- cpu : "1" ,
48
- memory : "256Mi" ,
49
- } ,
50
- startupCpuBoost : true ,
51
- } ,
52
- } ,
53
- ] ,
54
- containerConcurrency : backend . DEFAULT_CONCURRENCY , // Default for CPU >= 1
55
- } ,
56
- createTime : new Date ( ) . toISOString ( ) ,
57
- updateTime : new Date ( ) . toISOString ( ) ,
58
-
59
- lastModifier :
"[email protected] " ,
60
- etag : "test-etag" ,
61
- } ;
62
-
63
- const RUN_SERVICE_V2_INPUT_BASE : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
26
+ const BASE_RUN_SERVICE : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
64
27
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
65
28
labels : {
66
29
[ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
@@ -98,7 +61,7 @@ describe("runv2", () => {
98
61
httpsTrigger : { } ,
99
62
} ;
100
63
101
- expect ( runv2 . serviceFromEndpoint ( endpoint , IMAGE_URI ) ) . to . deep . equal ( RUN_SERVICE_V2_INPUT_BASE ) ;
64
+ expect ( runv2 . serviceFromEndpoint ( endpoint , IMAGE_URI ) ) . to . deep . equal ( BASE_RUN_SERVICE ) ;
102
65
} ) ;
103
66
104
67
it ( "should handle different codebase" , ( ) => {
@@ -108,10 +71,10 @@ describe("runv2", () => {
108
71
httpsTrigger : { } ,
109
72
} ;
110
73
const expectedServiceInput : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
111
- ...RUN_SERVICE_V2_INPUT_BASE ,
74
+ ...BASE_RUN_SERVICE ,
112
75
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
113
76
labels : {
114
- ...RUN_SERVICE_V2_INPUT_BASE . labels ,
77
+ ...BASE_RUN_SERVICE . labels ,
115
78
[ CODEBASE_LABEL ] : "my-codebase" ,
116
79
} ,
117
80
} ;
@@ -126,7 +89,7 @@ describe("runv2", () => {
126
89
} ;
127
90
const expectedServiceInput = JSON . parse (
128
91
JSON . stringify ( {
129
- ...RUN_SERVICE_V2_INPUT_BASE ,
92
+ ...BASE_RUN_SERVICE ,
130
93
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
131
94
} ) ,
132
95
) ;
@@ -145,7 +108,7 @@ describe("runv2", () => {
145
108
} ;
146
109
const expectedServiceInput = JSON . parse (
147
110
JSON . stringify ( {
148
- ...RUN_SERVICE_V2_INPUT_BASE ,
111
+ ...BASE_RUN_SERVICE ,
149
112
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
150
113
} ) ,
151
114
) ;
@@ -167,7 +130,7 @@ describe("runv2", () => {
167
130
} ;
168
131
const expectedServiceInput = JSON . parse (
169
132
JSON . stringify ( {
170
- ...RUN_SERVICE_V2_INPUT_BASE ,
133
+ ...BASE_RUN_SERVICE ,
171
134
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
172
135
} ) ,
173
136
) ;
@@ -185,7 +148,7 @@ describe("runv2", () => {
185
148
} ;
186
149
const expectedServiceInput = JSON . parse (
187
150
JSON . stringify ( {
188
- ...RUN_SERVICE_V2_INPUT_BASE ,
151
+ ...BASE_RUN_SERVICE ,
189
152
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
190
153
} ) ,
191
154
) ;
@@ -203,7 +166,7 @@ describe("runv2", () => {
203
166
} ;
204
167
const expectedServiceInput = JSON . parse (
205
168
JSON . stringify ( {
206
- ...RUN_SERVICE_V2_INPUT_BASE ,
169
+ ...BASE_RUN_SERVICE ,
207
170
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ FUNCTION_ID . toLowerCase ( ) } ` ,
208
171
} ) ,
209
172
) ;
@@ -227,8 +190,8 @@ describe("runv2", () => {
227
190
228
191
describe ( "endpointFromService" , ( ) => {
229
192
it ( "should copy a minimal service" , ( ) => {
230
- const service : runv2 . Service = {
231
- ...RUN_SERVICE_V2_OUTPUT_BASE ,
193
+ const service : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
194
+ ...BASE_RUN_SERVICE ,
232
195
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
233
196
labels : {
234
197
[ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
@@ -274,8 +237,8 @@ describe("runv2", () => {
274
237
} ) ;
275
238
276
239
it ( "should detect a service that's GCF managed" , ( ) => {
277
- const service : runv2 . Service = {
278
- ...RUN_SERVICE_V2_OUTPUT_BASE ,
240
+ const service : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
241
+ ...BASE_RUN_SERVICE ,
279
242
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
280
243
labels : {
281
244
[ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
@@ -323,8 +286,8 @@ describe("runv2", () => {
323
286
} ) ;
324
287
325
288
it ( "should derive id from FUNCTION_TARGET_ANNOTATION if FUNCTION_ID_ANNOTATION is missing" , ( ) => {
326
- const service : runv2 . Service = {
327
- ...RUN_SERVICE_V2_OUTPUT_BASE ,
289
+ const service : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
290
+ ...BASE_RUN_SERVICE ,
328
291
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
329
292
labels : {
330
293
[ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
@@ -348,8 +311,8 @@ describe("runv2", () => {
348
311
} ) ;
349
312
350
313
it ( "should derive id from service name part if FUNCTION_ID_ANNOTATION and FUNCTION_TARGET_ANNOTATION are missing" , ( ) => {
351
- const service : runv2 . Service = {
352
- ...RUN_SERVICE_V2_OUTPUT_BASE ,
314
+ const service : Omit < runv2 . Service , runv2 . ServiceOutputFields > = {
315
+ ...BASE_RUN_SERVICE ,
353
316
name : `projects/${ PROJECT_ID } /locations/${ LOCATION } /services/${ SERVICE_ID } ` ,
354
317
labels : {
355
318
[ runv2 . RUNTIME_LABEL ] : latest ( "nodejs" ) ,
@@ -373,7 +336,7 @@ describe("runv2", () => {
373
336
} ) ;
374
337
375
338
it ( "should copy env vars and secrets" , ( ) => {
376
- const service : runv2 . Service = JSON . parse ( JSON . stringify ( RUN_SERVICE_V2_OUTPUT_BASE ) ) ;
339
+ const service : runv2 . Service = JSON . parse ( JSON . stringify ( BASE_RUN_SERVICE ) ) ;
377
340
service . template . containers ! [ 0 ] . env = [
378
341
{ name : "FOO" , value : "bar" } ,
379
342
{
@@ -395,7 +358,7 @@ describe("runv2", () => {
395
358
} ) ;
396
359
397
360
it ( "should copy concurrency, min/max instances" , ( ) => {
398
- const service : runv2 . Service = JSON . parse ( JSON . stringify ( RUN_SERVICE_V2_OUTPUT_BASE ) ) ;
361
+ const service : runv2 . Service = JSON . parse ( JSON . stringify ( BASE_RUN_SERVICE ) ) ;
399
362
service . template . containerConcurrency = 10 ;
400
363
service . annotations ! [ runv2 . MIN_INSTANCES_ANNOTATION ] = "2" ;
401
364
service . annotations ! [ runv2 . MAX_INSTANCES_ANNOTATION ] = "5" ;
@@ -447,4 +410,4 @@ describe("runv2", () => {
447
410
expect ( runv2 . endpointFromService ( service ) ) . to . deep . equal ( expectedEndpoint ) ;
448
411
} ) ;
449
412
} ) ;
450
- } ) ;
413
+ } ) ;
0 commit comments