@@ -29,13 +29,15 @@ import { zipDir } from '../src/util';
29
29
30
30
const { TEST_PROJECT_ID , TEST_SERVICE_ACCOUNT_EMAIL , TEST_SECRET_VERSION_NAME } = process . env ;
31
31
const TEST_LOCATION = 'us-central1' ;
32
- const TEST_FUNCTION_NAME = 'test-' + crypto . randomBytes ( 12 ) . toString ( 'hex' ) ;
32
+ const TEST_SEED = crypto . randomBytes ( 12 ) . toString ( 'hex' ) . toLowerCase ( ) ;
33
+ const TEST_SEED_UPPER = TEST_SEED . toUpperCase ( ) ;
34
+ const TEST_FUNCTION_NAME = `unit-${ TEST_SEED } ` ;
33
35
34
36
test (
35
37
'lifecycle' ,
36
38
{
37
39
concurrency : true ,
38
- skip : skipIfMissingEnv ( 'TEST_PROJECT_ID' , 'TEST_LOCATION ') ,
40
+ skip : skipIfMissingEnv ( 'TEST_AUTHENTICATED ' ) ,
39
41
} ,
40
42
async ( suite ) => {
41
43
// Always try to delete the function
52
54
}
53
55
} ) ;
54
56
55
- suite . test ( 'can create, read, update, and delete' , async ( ) => {
57
+ await suite . test ( 'can create, read, update, and delete' , async ( ) => {
56
58
const secret = new SecretName ( TEST_SECRET_VERSION_NAME ) ;
57
59
58
60
const client = new CloudFunctionsClient ( {
@@ -75,39 +77,50 @@ test(
75
77
name : TEST_FUNCTION_NAME ,
76
78
description : 'test function' ,
77
79
environment : Environment . GEN_2 ,
78
- labels : { key1 : 'value1' , key2 : 'value2' } ,
80
+ labels : {
81
+ [ `label1-${ TEST_SEED } ` ] : `value1_${ TEST_SEED } ` ,
82
+ [ `label2-${ TEST_SEED } ` ] : `value2_${ TEST_SEED } ` ,
83
+ } ,
79
84
80
85
buildConfig : {
81
86
runtime : 'nodejs22' ,
82
87
entryPoint : 'helloWorld' ,
83
- source : sourceUploadResp ,
84
- environmentVariables : { BUILDKEY1 : 'VALUE1' , BUILDKEY2 : 'VALUE2' } ,
88
+ source : {
89
+ storageSource : sourceUploadResp . storageSource ,
90
+ } ,
91
+ environmentVariables : {
92
+ [ `BUILD_ENV_KEY1_${ TEST_SEED_UPPER } ` ] : `VALUE1_${ TEST_SEED } ` ,
93
+ [ `BUILD_ENV_KEY2_${ TEST_SEED_UPPER } ` ] : `VALUE2_${ TEST_SEED } ` ,
94
+ } ,
85
95
} ,
86
96
87
97
serviceConfig : {
88
98
allTrafficOnLatestRevision : true ,
89
99
availableCpu : '1' ,
90
- availableMemory : '512m' ,
91
- environmentVariables : { KEY1 : 'VALUE1' , KEY2 : 'VALUE2' } ,
100
+ availableMemory : '512Mi' ,
101
+ environmentVariables : {
102
+ [ `SERVICE_ENV_KEY1_${ TEST_SEED_UPPER } ` ] : `VALUE1_${ TEST_SEED } ` ,
103
+ [ `SERVICE_ENV_KEY2_${ TEST_SEED_UPPER } ` ] : `VALUE2_${ TEST_SEED } ` ,
104
+ } ,
92
105
ingressSettings : IngressSettings . ALLOW_ALL ,
93
106
maxInstanceCount : 5 ,
94
107
minInstanceCount : 2 ,
95
108
secretEnvironmentVariables : [
96
109
{
97
- key : 'SECRET1' ,
110
+ key : `SECRET1_ ${ TEST_SEED_UPPER } ` ,
98
111
projectId : secret . project ,
99
112
secret : secret . name ,
100
113
version : secret . version ,
101
114
} ,
102
115
] ,
103
116
secretVolumes : [
104
117
{
105
- mountPath : ' /etc/secrets/one' ,
118
+ mountPath : ` /etc/secrets/one_ ${ TEST_SEED } ` ,
106
119
projectId : secret . project ,
107
120
secret : secret . name ,
108
121
versions : [
109
122
{
110
- path : '/ value1' ,
123
+ path : 'value1' ,
111
124
version : secret . version ,
112
125
} ,
113
126
] ,
@@ -119,45 +132,55 @@ test(
119
132
} ;
120
133
121
134
// Create
122
- const createResp = await client . create ( cf ) ;
135
+ const createResp = await client . create ( cf , {
136
+ onDebug : ( f ) => {
137
+ process . stdout . write ( '\n\n\n\n' ) ;
138
+ process . stdout . write ( f ( ) ) ;
139
+ process . stdout . write ( '\n\n\n\n' ) ;
140
+ } ,
141
+ } ) ;
123
142
assert . ok ( createResp ?. url ) ;
124
143
125
144
// Read
126
145
const getResp = await client . get ( cf . name ) ;
127
146
assert . ok ( getResp . name . endsWith ( TEST_FUNCTION_NAME ) ) ; // The response is the fully-qualified name
128
147
assert . deepStrictEqual ( getResp . description , 'test function' ) ;
129
- assert . deepStrictEqual ( getResp . labels , { key1 : 'value1' , key2 : 'value2' } ) ;
130
- assert . deepStrictEqual ( getResp . buildConfig . runtime , 'nodejs20' ) ;
148
+ assert . deepStrictEqual ( getResp . labels , {
149
+ [ `label1-${ TEST_SEED } ` ] : `value1_${ TEST_SEED } ` ,
150
+ [ `label2-${ TEST_SEED } ` ] : `value2_${ TEST_SEED } ` ,
151
+ } ) ;
152
+ assert . deepStrictEqual ( getResp . buildConfig . runtime , 'nodejs22' ) ;
131
153
assert . deepStrictEqual ( getResp . buildConfig . environmentVariables , {
132
- BUILDKEY1 : 'VALUE1' ,
133
- BUILDKEY2 : 'VALUE2' ,
154
+ [ `BUILD_ENV_KEY1_ ${ TEST_SEED_UPPER } ` ] : `VALUE1_ ${ TEST_SEED } ` ,
155
+ [ `BUILD_ENV_KEY2_ ${ TEST_SEED_UPPER } ` ] : `VALUE2_ ${ TEST_SEED } ` ,
134
156
} ) ;
135
157
assert . deepStrictEqual ( getResp . buildConfig . entryPoint , 'helloWorld' ) ;
136
- assert . deepStrictEqual ( getResp . serviceConfig . availableCpu , 1 ) ;
137
- assert . deepStrictEqual ( getResp . serviceConfig . availableMemory , 512 ) ;
158
+ assert . deepStrictEqual ( getResp . serviceConfig . availableCpu , '1' ) ;
159
+ assert . deepStrictEqual ( getResp . serviceConfig . availableMemory , '512Mi' ) ;
138
160
assert . deepStrictEqual ( getResp . serviceConfig . environmentVariables , {
139
- KEY1 : 'VALUE1' ,
140
- KEY2 : 'VALUE2' ,
161
+ LOG_EXECUTION_ID : 'true' , // inserted by GCP
162
+ [ `SERVICE_ENV_KEY1_${ TEST_SEED_UPPER } ` ] : `VALUE1_${ TEST_SEED } ` ,
163
+ [ `SERVICE_ENV_KEY2_${ TEST_SEED_UPPER } ` ] : `VALUE2_${ TEST_SEED } ` ,
141
164
} ) ;
142
165
assert . deepStrictEqual ( getResp . serviceConfig . ingressSettings , 'ALLOW_ALL' ) ;
143
166
assert . deepStrictEqual ( getResp . serviceConfig . maxInstanceCount , 5 ) ;
144
167
assert . deepStrictEqual ( getResp . serviceConfig . minInstanceCount , 2 ) ;
145
168
assert . deepStrictEqual ( getResp . serviceConfig . secretEnvironmentVariables , [
146
169
{
147
- key : 'SECRET1' ,
170
+ key : `SECRET1_ ${ TEST_SEED_UPPER } ` ,
148
171
projectId : secret . project ,
149
172
secret : secret . name ,
150
173
version : secret . version ,
151
174
} ,
152
175
] ) ;
153
176
assert . deepStrictEqual ( getResp . serviceConfig . secretVolumes , [
154
177
{
155
- mountPath : ' /etc/secrets/one' ,
178
+ mountPath : ` /etc/secrets/one_ ${ TEST_SEED } ` ,
156
179
projectId : secret . project ,
157
180
secret : secret . name ,
158
181
versions : [
159
182
{
160
- path : '/ value1' ,
183
+ path : 'value1' ,
161
184
version : secret . version ,
162
185
} ,
163
186
] ,
@@ -175,38 +198,49 @@ test(
175
198
const cf2 : CloudFunction = {
176
199
name : TEST_FUNCTION_NAME ,
177
200
description : 'test function2' ,
178
- labels : { key3 : 'value3' , key4 : 'value4' } ,
201
+ labels : {
202
+ [ `label3-${ TEST_SEED } ` ] : `value3_${ TEST_SEED } ` ,
203
+ [ `label4-${ TEST_SEED } ` ] : `value4_${ TEST_SEED } ` ,
204
+ } ,
179
205
180
206
buildConfig : {
181
207
runtime : 'nodejs20' ,
182
208
entryPoint : 'helloWorld' ,
183
- source : sourceUploadUpdateResp ,
184
- environmentVariables : { BUILDKEY3 : 'VALUE3' , BUILDKEY4 : 'VALUE4' } ,
209
+ source : {
210
+ storageSource : sourceUploadResp . storageSource ,
211
+ } ,
212
+ environmentVariables : {
213
+ [ `BUILD_ENV_KEY3_${ TEST_SEED_UPPER } ` ] : `VALUE3_${ TEST_SEED } ` ,
214
+ [ `BUILD_ENV_KEY4_${ TEST_SEED_UPPER } ` ] : `VALUE4_${ TEST_SEED } ` ,
215
+ } ,
185
216
} ,
186
217
187
218
serviceConfig : {
188
219
allTrafficOnLatestRevision : true ,
189
- availableMemory : '256Mi' ,
190
- environmentVariables : { KEY3 : 'VALUE3' , KEY4 : 'VALUE4' } ,
220
+ availableMemory : '1Gi' ,
221
+ environmentVariables : {
222
+ [ `SERVICE_ENV_KEY3_${ TEST_SEED_UPPER } ` ] : `VALUE3_${ TEST_SEED } ` ,
223
+ [ `SERVICE_ENV_KEY4_${ TEST_SEED_UPPER } ` ] : `VALUE4_${ TEST_SEED } ` ,
224
+ } ,
191
225
ingressSettings : IngressSettings . ALLOW_INTERNAL_AND_GCLB ,
192
226
maxInstanceCount : 3 ,
193
227
minInstanceCount : 1 ,
194
228
secretEnvironmentVariables : [
195
229
{
196
- key : 'SECRET2' ,
230
+ key : `SECRET2_ ${ TEST_SEED_UPPER } ` ,
197
231
projectId : secret . project ,
198
232
secret : secret . name ,
199
233
version : secret . version ,
200
234
} ,
201
235
] ,
202
236
secretVolumes : [
203
237
{
204
- mountPath : ' /etc/secrets/two' ,
238
+ mountPath : ` /etc/secrets/two_ ${ TEST_SEED } ` ,
205
239
projectId : secret . project ,
206
240
secret : secret . name ,
207
241
versions : [
208
242
{
209
- path : '/ value2' ,
243
+ path : 'value2' ,
210
244
version : secret . version ,
211
245
} ,
212
246
] ,
@@ -217,40 +251,50 @@ test(
217
251
} ,
218
252
} ;
219
253
220
- const patchResp = await client . patch ( cf2 ) ;
254
+ const patchResp = await client . patch ( cf2 , {
255
+ onDebug : ( f ) => {
256
+ process . stdout . write ( '\n\n\n\n' ) ;
257
+ process . stdout . write ( f ( ) ) ;
258
+ process . stdout . write ( '\n\n\n\n' ) ;
259
+ } ,
260
+ } ) ;
221
261
assert . ok ( patchResp . name . endsWith ( TEST_FUNCTION_NAME ) ) ; // The response is the fully-qualified name
222
262
assert . deepStrictEqual ( patchResp . description , 'test function2' ) ;
223
- assert . deepStrictEqual ( patchResp . labels , { key3 : 'value3' , key4 : 'value4' } ) ;
263
+ assert . deepStrictEqual ( patchResp . labels , {
264
+ [ `label3-${ TEST_SEED } ` ] : `value3_${ TEST_SEED } ` ,
265
+ [ `label4-${ TEST_SEED } ` ] : `value4_${ TEST_SEED } ` ,
266
+ } ) ;
224
267
assert . deepStrictEqual ( patchResp . buildConfig . runtime , 'nodejs20' ) ;
225
268
assert . deepStrictEqual ( patchResp . buildConfig . entryPoint , 'helloWorld' ) ;
226
269
assert . deepStrictEqual ( patchResp . buildConfig . environmentVariables , {
227
- BUILDKEY3 : 'VALUE3' ,
228
- BUILDKEY4 : 'VALUE4' ,
270
+ [ `BUILD_ENV_KEY3_ ${ TEST_SEED_UPPER } ` ] : `VALUE3_ ${ TEST_SEED } ` ,
271
+ [ `BUILD_ENV_KEY4_ ${ TEST_SEED_UPPER } ` ] : `VALUE4_ ${ TEST_SEED } ` ,
229
272
} ) ;
230
- assert . deepStrictEqual ( patchResp . serviceConfig . availableMemory , '256 ' ) ;
273
+ assert . deepStrictEqual ( patchResp . serviceConfig . availableMemory , '1Gi ' ) ;
231
274
assert . deepStrictEqual ( patchResp . serviceConfig . environmentVariables , {
232
- KEY3 : 'VALUE3' ,
233
- KEY4 : 'VALUE4' ,
275
+ LOG_EXECUTION_ID : 'true' , // inserted by GCP
276
+ [ `SERVICE_ENV_KEY3_${ TEST_SEED_UPPER } ` ] : `VALUE3_${ TEST_SEED } ` ,
277
+ [ `SERVICE_ENV_KEY4_${ TEST_SEED_UPPER } ` ] : `VALUE4_${ TEST_SEED } ` ,
234
278
} ) ;
235
279
assert . deepStrictEqual ( patchResp . serviceConfig . ingressSettings , 'ALLOW_INTERNAL_AND_GCLB' ) ;
236
280
assert . deepStrictEqual ( patchResp . serviceConfig . maxInstanceCount , 3 ) ;
237
281
assert . deepStrictEqual ( patchResp . serviceConfig . minInstanceCount , 1 ) ;
238
282
assert . deepStrictEqual ( patchResp . serviceConfig . secretEnvironmentVariables , [
239
283
{
240
- key : 'SECRET2' ,
284
+ key : `SECRET2_ ${ TEST_SEED_UPPER } ` ,
241
285
projectId : secret . project ,
242
286
secret : secret . name ,
243
287
version : secret . version ,
244
288
} ,
245
289
] ) ;
246
290
assert . deepStrictEqual ( patchResp . serviceConfig . secretVolumes , [
247
291
{
248
- mountPath : ' /etc/secrets/two' ,
292
+ mountPath : ` /etc/secrets/two_ ${ TEST_SEED } ` ,
249
293
projectId : secret . project ,
250
294
secret : secret . name ,
251
295
versions : [
252
296
{
253
- path : '/ value2' ,
297
+ path : 'value2' ,
254
298
version : secret . version ,
255
299
} ,
256
300
] ,
0 commit comments