@google-cloud/agones-sdk 1.55.0 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/biome.json +24 -0
- package/package.json +7 -7
- package/spec/agonesSDK.spec.js +481 -467
- package/spec/alphaAgonesSDK.spec.js +288 -254
- package/spec/betaAgonesSDK.spec.js +427 -419
- package/spec/support/jasmine.json +6 -8
- package/src/agonesSDK.d.ts +25 -22
- package/src/agonesSDK.js +13 -11
- package/src/alpha.d.ts +7 -7
- package/src/alpha.js +130 -130
- package/src/beta.d.ts +13 -13
- package/src/beta.js +248 -248
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/.eslintrc.json +0 -18
package/spec/agonesSDK.spec.js
CHANGED
|
@@ -1,467 +1,481 @@
|
|
|
1
|
-
// Copyright 2019 Google LLC All Rights Reserved.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
const stream = require(
|
|
16
|
-
|
|
17
|
-
const grpc = require(
|
|
18
|
-
|
|
19
|
-
const messages = require(
|
|
20
|
-
|
|
21
|
-
const AgonesSDK = require(
|
|
22
|
-
const Alpha = require(
|
|
23
|
-
|
|
24
|
-
describe(
|
|
25
|
-
let agonesSDK;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
agonesSDK = new AgonesSDK();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe(
|
|
32
|
-
it(
|
|
33
|
-
|
|
34
|
-
expect(port).toEqual(
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it(
|
|
38
|
-
process.env.AGONES_SDK_GRPC_PORT =
|
|
39
|
-
|
|
40
|
-
expect(port).toEqual(
|
|
41
|
-
delete process.env.AGONES_SDK_GRPC_PORT;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it(
|
|
45
|
-
process.env.AGONES_SDK_GRPC_PORT =
|
|
46
|
-
|
|
47
|
-
expect(port).toEqual(
|
|
48
|
-
delete process.env.AGONES_SDK_GRPC_PORT;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe(
|
|
53
|
-
it(
|
|
54
|
-
spyOn(agonesSDK.client,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
agonesSDK.health()
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
agonesSDK.health()
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
expect(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
expect(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
spyOn(agonesSDK.client,
|
|
428
|
-
await agonesSDK.close();
|
|
429
|
-
expect(
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
it(
|
|
449
|
-
spyOn(agonesSDK.client,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
1
|
+
// Copyright 2019 Google LLC All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
const stream = require("node:stream");
|
|
16
|
+
|
|
17
|
+
const grpc = require("@grpc/grpc-js");
|
|
18
|
+
|
|
19
|
+
const messages = require("../lib/sdk_pb");
|
|
20
|
+
|
|
21
|
+
const AgonesSDK = require("../src/agonesSDK");
|
|
22
|
+
const Alpha = require("../src/alpha");
|
|
23
|
+
|
|
24
|
+
describe("AgonesSDK", () => {
|
|
25
|
+
let agonesSDK;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
agonesSDK = new AgonesSDK();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("port", () => {
|
|
32
|
+
it("returns the default port if $AGONES_SDK_GRPC_PORT is not defined", async () => {
|
|
33
|
+
const port = agonesSDK.port;
|
|
34
|
+
expect(port).toEqual("9357");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("returns a valid port set in $AGONES_SDK_GRPC_PORT", async () => {
|
|
38
|
+
process.env.AGONES_SDK_GRPC_PORT = "6789";
|
|
39
|
+
const port = agonesSDK.port;
|
|
40
|
+
expect(port).toEqual("6789");
|
|
41
|
+
delete process.env.AGONES_SDK_GRPC_PORT;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns an invalid port set in $AGONES_SDK_GRPC_PORT", async () => {
|
|
45
|
+
process.env.AGONES_SDK_GRPC_PORT = "foo";
|
|
46
|
+
const port = agonesSDK.port;
|
|
47
|
+
expect(port).toEqual("foo");
|
|
48
|
+
delete process.env.AGONES_SDK_GRPC_PORT;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("connect", () => {
|
|
53
|
+
it("calls the server and handles success", async () => {
|
|
54
|
+
spyOn(agonesSDK.client, "waitForReady").and.callFake(
|
|
55
|
+
(_deadline, callback) => {
|
|
56
|
+
const result = new messages.Empty();
|
|
57
|
+
callback(undefined, result);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
const result = await agonesSDK.connect();
|
|
61
|
+
expect(agonesSDK.client.waitForReady).toHaveBeenCalled();
|
|
62
|
+
expect(result).toEqual(undefined);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("calls the server and handles failure", async () => {
|
|
66
|
+
spyOn(agonesSDK.client, "waitForReady").and.callFake(
|
|
67
|
+
(_deadline, callback) => {
|
|
68
|
+
callback("error", undefined);
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
try {
|
|
72
|
+
await agonesSDK.connect();
|
|
73
|
+
fail();
|
|
74
|
+
} catch (error) {
|
|
75
|
+
expect(agonesSDK.client.waitForReady).toHaveBeenCalled();
|
|
76
|
+
expect(error).toEqual("error");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("ready", () => {
|
|
82
|
+
it("calls the server and handles success", async () => {
|
|
83
|
+
spyOn(agonesSDK.client, "ready").and.callFake((_request, callback) => {
|
|
84
|
+
const result = new messages.Empty();
|
|
85
|
+
callback(undefined, result);
|
|
86
|
+
});
|
|
87
|
+
const result = await agonesSDK.ready();
|
|
88
|
+
expect(agonesSDK.client.ready).toHaveBeenCalled();
|
|
89
|
+
expect(result).toEqual({});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("calls the server and handles failure", async () => {
|
|
93
|
+
spyOn(agonesSDK.client, "ready").and.callFake((_request, callback) => {
|
|
94
|
+
callback("error", undefined);
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
await agonesSDK.ready();
|
|
98
|
+
fail();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
expect(agonesSDK.client.ready).toHaveBeenCalled();
|
|
101
|
+
expect(error).toEqual("error");
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("allocate", () => {
|
|
107
|
+
it("calls the server and handles success", async () => {
|
|
108
|
+
spyOn(agonesSDK.client, "allocate").and.callFake((_request, callback) => {
|
|
109
|
+
const result = new messages.Empty();
|
|
110
|
+
callback(undefined, result);
|
|
111
|
+
});
|
|
112
|
+
const result = await agonesSDK.allocate();
|
|
113
|
+
expect(agonesSDK.client.allocate).toHaveBeenCalled();
|
|
114
|
+
expect(result).toEqual({});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("calls the server and handles failure", async () => {
|
|
118
|
+
spyOn(agonesSDK.client, "allocate").and.callFake((_request, callback) => {
|
|
119
|
+
callback("error", undefined);
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
await agonesSDK.allocate();
|
|
123
|
+
fail();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
expect(agonesSDK.client.allocate).toHaveBeenCalled();
|
|
126
|
+
expect(error).toEqual("error");
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("shutdown", () => {
|
|
132
|
+
it("calls the server and handles success", async () => {
|
|
133
|
+
spyOn(agonesSDK.client, "shutdown").and.callFake((_request, callback) => {
|
|
134
|
+
const result = new messages.Empty();
|
|
135
|
+
callback(undefined, result);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const result = await agonesSDK.shutdown();
|
|
139
|
+
expect(agonesSDK.client.shutdown).toHaveBeenCalled();
|
|
140
|
+
expect(result).toEqual({});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("calls the server and handles failure", async () => {
|
|
144
|
+
spyOn(agonesSDK.client, "shutdown").and.callFake((_request, callback) => {
|
|
145
|
+
callback("error", undefined);
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
await agonesSDK.shutdown();
|
|
149
|
+
fail();
|
|
150
|
+
} catch (error) {
|
|
151
|
+
expect(agonesSDK.client.shutdown).toHaveBeenCalled();
|
|
152
|
+
expect(error).toEqual("error");
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("health", () => {
|
|
158
|
+
it("calls the server and passes calls to stream", async () => {
|
|
159
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
160
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
161
|
+
return stream;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
agonesSDK.health();
|
|
165
|
+
expect(agonesSDK.client.health).toHaveBeenCalled();
|
|
166
|
+
expect(stream.write).toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("uses the same stream for subsequent calls", async () => {
|
|
170
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
171
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
172
|
+
return stream;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
agonesSDK.health();
|
|
176
|
+
agonesSDK.health();
|
|
177
|
+
expect(agonesSDK.client.health.calls.count()).toEqual(1);
|
|
178
|
+
expect(stream.write.calls.count()).toEqual(2);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("calls the server and silently handles the internal error message", async () => {
|
|
182
|
+
spyOn(agonesSDK.client, "health").and.callFake((callback) => {
|
|
183
|
+
callback("error", undefined);
|
|
184
|
+
});
|
|
185
|
+
try {
|
|
186
|
+
agonesSDK.health();
|
|
187
|
+
fail();
|
|
188
|
+
} catch (error) {
|
|
189
|
+
expect(agonesSDK.client.health).toHaveBeenCalled();
|
|
190
|
+
expect(error).not.toEqual("error");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("calls the server and handles stream write error if callback provided", async () => {
|
|
195
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
196
|
+
stream.write.and.callFake((_chunk, _encoding, callback) => {
|
|
197
|
+
callback("error");
|
|
198
|
+
});
|
|
199
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
200
|
+
return stream;
|
|
201
|
+
});
|
|
202
|
+
try {
|
|
203
|
+
agonesSDK.health((error) => {
|
|
204
|
+
expect(error).toEqual("error");
|
|
205
|
+
});
|
|
206
|
+
} catch (error) {
|
|
207
|
+
fail(error);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("calls the server and re throws stream write error if no callback", async () => {
|
|
212
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
213
|
+
stream.write.and.callFake((_chunk, _encoding, callback) => {
|
|
214
|
+
callback("error");
|
|
215
|
+
});
|
|
216
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
217
|
+
return stream;
|
|
218
|
+
});
|
|
219
|
+
try {
|
|
220
|
+
agonesSDK.health();
|
|
221
|
+
fail();
|
|
222
|
+
} catch (error) {
|
|
223
|
+
expect(agonesSDK.client.health).toHaveBeenCalled();
|
|
224
|
+
expect(error).toEqual("error");
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("does not call error callback if there was no stream error", async () => {
|
|
229
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
230
|
+
stream.write.and.callFake((_chunk, _encoding, callback) => {
|
|
231
|
+
callback();
|
|
232
|
+
});
|
|
233
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
234
|
+
return stream;
|
|
235
|
+
});
|
|
236
|
+
agonesSDK.health(() => {
|
|
237
|
+
fail();
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("calls the server and handles stream completing", async () => {
|
|
242
|
+
const stream = jasmine.createSpyObj("stream", ["write", "on"]);
|
|
243
|
+
spyOn(agonesSDK.client, "health").and.callFake((callback) => {
|
|
244
|
+
const result = new messages.Empty();
|
|
245
|
+
callback(undefined, result);
|
|
246
|
+
return stream;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
agonesSDK.health();
|
|
250
|
+
expect(agonesSDK.client.health).toHaveBeenCalled();
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe("getGameServer", () => {
|
|
255
|
+
it("calls the server and handles the response", async () => {
|
|
256
|
+
spyOn(agonesSDK.client, "getGameServer").and.callFake(
|
|
257
|
+
(_request, callback) => {
|
|
258
|
+
const status = new messages.GameServer.Status();
|
|
259
|
+
status.setState("up");
|
|
260
|
+
const gameServer = new messages.GameServer();
|
|
261
|
+
gameServer.setStatus(status);
|
|
262
|
+
callback(undefined, gameServer);
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const gameServer = await agonesSDK.getGameServer();
|
|
267
|
+
expect(agonesSDK.client.getGameServer).toHaveBeenCalled();
|
|
268
|
+
expect(gameServer).toBeDefined();
|
|
269
|
+
expect(gameServer.status).toBeDefined();
|
|
270
|
+
expect(gameServer.status.state).toEqual("up");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("calls the server and handles failure", async () => {
|
|
274
|
+
spyOn(agonesSDK.client, "getGameServer").and.callFake(
|
|
275
|
+
(_request, callback) => {
|
|
276
|
+
callback("error", undefined);
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
try {
|
|
280
|
+
await agonesSDK.getGameServer();
|
|
281
|
+
fail();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
expect(agonesSDK.client.getGameServer).toHaveBeenCalled();
|
|
284
|
+
expect(error).toEqual("error");
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe("watchGameServer", () => {
|
|
290
|
+
it("calls the server and passes events to the callback", async () => {
|
|
291
|
+
const serverStream = stream.Readable({ read: () => undefined });
|
|
292
|
+
spyOn(agonesSDK.client, "watchGameServer").and.callFake(() => {
|
|
293
|
+
return serverStream;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const callback = jasmine.createSpy("callback");
|
|
297
|
+
agonesSDK.watchGameServer(callback);
|
|
298
|
+
expect(agonesSDK.client.watchGameServer).toHaveBeenCalled();
|
|
299
|
+
|
|
300
|
+
const status = new messages.GameServer.Status();
|
|
301
|
+
status.setState("up");
|
|
302
|
+
const gameServer = new messages.GameServer();
|
|
303
|
+
gameServer.setStatus(status);
|
|
304
|
+
serverStream.emit("data", gameServer);
|
|
305
|
+
|
|
306
|
+
expect(callback).toHaveBeenCalled();
|
|
307
|
+
const callbackArgs = callback.calls.argsFor(0)[0];
|
|
308
|
+
expect(callbackArgs.status).toBeDefined();
|
|
309
|
+
expect(callbackArgs.status.state).toEqual("up");
|
|
310
|
+
});
|
|
311
|
+
it("calls the server and passes errors to the optional error callback", async () => {
|
|
312
|
+
const serverStream = stream.Readable({ read: () => undefined });
|
|
313
|
+
spyOn(agonesSDK.client, "watchGameServer").and.callFake(() => {
|
|
314
|
+
return serverStream;
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const callback = jasmine.createSpy("callback");
|
|
318
|
+
const errorCallback = jasmine.createSpy("errorCallback");
|
|
319
|
+
agonesSDK.watchGameServer(callback, errorCallback);
|
|
320
|
+
|
|
321
|
+
const error = {
|
|
322
|
+
code: grpc.status.CANCELLED,
|
|
323
|
+
};
|
|
324
|
+
serverStream.emit("error", error);
|
|
325
|
+
expect(errorCallback).toHaveBeenCalled();
|
|
326
|
+
const errorCallbackArgs = errorCallback.calls.argsFor(0)[0];
|
|
327
|
+
expect(errorCallbackArgs).toEqual(error);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("setLabel", () => {
|
|
332
|
+
it("calls the server and handles success", async () => {
|
|
333
|
+
spyOn(agonesSDK.client, "setLabel").and.callFake((_request, callback) => {
|
|
334
|
+
const result = new messages.Empty();
|
|
335
|
+
callback(undefined, result);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const result = await agonesSDK.setLabel("key", "value");
|
|
339
|
+
expect(agonesSDK.client.setLabel).toHaveBeenCalled();
|
|
340
|
+
expect(result).toEqual({});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("passes arguments to the server", async () => {
|
|
344
|
+
spyOn(agonesSDK.client, "setLabel").and.callFake((_request, callback) => {
|
|
345
|
+
const result = new messages.Empty();
|
|
346
|
+
callback(undefined, result);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
await agonesSDK.setLabel("key", "value");
|
|
350
|
+
expect(agonesSDK.client.setLabel).toHaveBeenCalled();
|
|
351
|
+
const request = agonesSDK.client.setLabel.calls.argsFor(0)[0];
|
|
352
|
+
expect(request.getKey()).toEqual("key");
|
|
353
|
+
expect(request.getValue()).toEqual("value");
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("calls the server and handles failure", async () => {
|
|
357
|
+
spyOn(agonesSDK.client, "setLabel").and.callFake((_request, callback) => {
|
|
358
|
+
callback("error", undefined);
|
|
359
|
+
});
|
|
360
|
+
try {
|
|
361
|
+
await agonesSDK.setLabel("key", "value");
|
|
362
|
+
fail();
|
|
363
|
+
} catch (error) {
|
|
364
|
+
expect(agonesSDK.client.setLabel).toHaveBeenCalled();
|
|
365
|
+
expect(error).toEqual("error");
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe("setAnnotation", () => {
|
|
371
|
+
it("calls the server and handles success", async () => {
|
|
372
|
+
spyOn(agonesSDK.client, "setAnnotation").and.callFake(
|
|
373
|
+
(_request, callback) => {
|
|
374
|
+
const result = new messages.Empty();
|
|
375
|
+
callback(undefined, result);
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
const result = await agonesSDK.setAnnotation("key", "value");
|
|
380
|
+
expect(agonesSDK.client.setAnnotation).toHaveBeenCalled();
|
|
381
|
+
expect(result).toEqual({});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("passes arguments to the server", async () => {
|
|
385
|
+
spyOn(agonesSDK.client, "setAnnotation").and.callFake(
|
|
386
|
+
(_request, callback) => {
|
|
387
|
+
const result = new messages.Empty();
|
|
388
|
+
callback(undefined, result);
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
await agonesSDK.setAnnotation("key", "value");
|
|
393
|
+
expect(agonesSDK.client.setAnnotation).toHaveBeenCalled();
|
|
394
|
+
const request = agonesSDK.client.setAnnotation.calls.argsFor(0)[0];
|
|
395
|
+
expect(request.getKey()).toEqual("key");
|
|
396
|
+
expect(request.getValue()).toEqual("value");
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("calls the server and handles failure", async () => {
|
|
400
|
+
spyOn(agonesSDK.client, "setAnnotation").and.callFake(
|
|
401
|
+
(_request, callback) => {
|
|
402
|
+
callback("error", undefined);
|
|
403
|
+
},
|
|
404
|
+
);
|
|
405
|
+
try {
|
|
406
|
+
await agonesSDK.setAnnotation("key", "value");
|
|
407
|
+
fail();
|
|
408
|
+
} catch (error) {
|
|
409
|
+
expect(agonesSDK.client.setAnnotation).toHaveBeenCalled();
|
|
410
|
+
expect(error).toEqual("error");
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
describe("close", () => {
|
|
416
|
+
it("closes the client connection when called", async () => {
|
|
417
|
+
spyOn(agonesSDK.client, "close");
|
|
418
|
+
await agonesSDK.close();
|
|
419
|
+
expect(agonesSDK.client.close).toHaveBeenCalled();
|
|
420
|
+
});
|
|
421
|
+
it("ends the health stream if set", async () => {
|
|
422
|
+
const stream = jasmine.createSpyObj("stream", ["end", "write", "on"]);
|
|
423
|
+
spyOn(agonesSDK.client, "health").and.callFake(() => {
|
|
424
|
+
return stream;
|
|
425
|
+
});
|
|
426
|
+
agonesSDK.health();
|
|
427
|
+
spyOn(agonesSDK.client, "close").and.callFake(() => {});
|
|
428
|
+
await agonesSDK.close();
|
|
429
|
+
expect(stream.end).toHaveBeenCalled();
|
|
430
|
+
});
|
|
431
|
+
it("cancels any watchers", async () => {
|
|
432
|
+
const serverStream = stream.Readable({ read: () => undefined });
|
|
433
|
+
spyOn(serverStream, "destroy").and.callThrough();
|
|
434
|
+
spyOn(agonesSDK.client, "watchGameServer").and.callFake(() => {
|
|
435
|
+
return serverStream;
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const callback = jasmine.createSpy("callback");
|
|
439
|
+
agonesSDK.watchGameServer(callback);
|
|
440
|
+
|
|
441
|
+
spyOn(agonesSDK.client, "close");
|
|
442
|
+
await agonesSDK.close();
|
|
443
|
+
expect(serverStream.destroy).toHaveBeenCalled();
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
describe("reserve", () => {
|
|
448
|
+
it("calls the server with duration parameter and handles success", async () => {
|
|
449
|
+
spyOn(agonesSDK.client, "reserve").and.callFake((_request, callback) => {
|
|
450
|
+
const result = new messages.Empty();
|
|
451
|
+
callback(undefined, result);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const result = await agonesSDK.reserve(10);
|
|
455
|
+
expect(agonesSDK.client.reserve).toHaveBeenCalled();
|
|
456
|
+
expect(result).toEqual({});
|
|
457
|
+
|
|
458
|
+
const request = agonesSDK.client.reserve.calls.argsFor(0)[0];
|
|
459
|
+
expect(request.getSeconds()).toEqual(10);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("calls the server and handles failure", async () => {
|
|
463
|
+
spyOn(agonesSDK.client, "reserve").and.callFake((_request, callback) => {
|
|
464
|
+
callback("error", undefined);
|
|
465
|
+
});
|
|
466
|
+
try {
|
|
467
|
+
await agonesSDK.reserve(10);
|
|
468
|
+
fail();
|
|
469
|
+
} catch (error) {
|
|
470
|
+
expect(agonesSDK.client.reserve).toHaveBeenCalled();
|
|
471
|
+
expect(error).toEqual("error");
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
describe("alpha", () => {
|
|
477
|
+
it("returns the alpha features class", () => {
|
|
478
|
+
expect(agonesSDK.alpha).toBeInstanceOf(Alpha);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
});
|