Skip to content

Commit 07637e5

Browse files
committed
fix: update @alicloud/fc20230330 from 4.6.8 - 4.7.4、add session pause and session resume
1 parent b901a4a commit 07637e5

6 files changed

Lines changed: 477 additions & 16 deletions

File tree

__tests__/ut/commands/session_test.ts

Lines changed: 279 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,136 @@ describe('Session', () => {
389389
});
390390
});
391391

392+
describe('pause', () => {
393+
beforeEach(() => {
394+
mockInputs.args = ['pause', '--session-id', 'session-123', '--qualifier', 'LATEST'];
395+
session = new Session(mockInputs);
396+
});
397+
398+
it('should pause session successfully', async () => {
399+
const mockResult = {
400+
sessionId: 'session-123',
401+
qualifier: 'LATEST',
402+
sessionStatus: 'Paused',
403+
};
404+
405+
mockFcSdk.pauseFunctionSession = jest.fn().mockResolvedValue(mockResult);
406+
407+
const result = await session.pause();
408+
expect(result).toEqual(mockResult);
409+
expect(mockFcSdk.pauseFunctionSession).toHaveBeenCalledWith(
410+
'test-function',
411+
'session-123',
412+
'LATEST',
413+
);
414+
});
415+
416+
it('should throw error when functionName is not specified', async () => {
417+
delete mockInputs.props.functionName;
418+
mockInputs.args = ['pause', '--session-id', 'session-123', '--qualifier', 'LATEST'];
419+
session = new Session(mockInputs);
420+
421+
await expect(session.pause()).rejects.toThrow(
422+
'functionName not specified, please specify --function-name',
423+
);
424+
});
425+
426+
it('should throw error when sessionId is not specified', async () => {
427+
mockInputs.args = ['pause', '--qualifier', 'LATEST'];
428+
session = new Session(mockInputs);
429+
430+
await expect(session.pause()).rejects.toThrow(
431+
'sessionId not specified, please specify --session-id',
432+
);
433+
});
434+
435+
it('should throw error when qualifier is not specified', async () => {
436+
mockInputs.args = ['pause', '--session-id', 'session-123'];
437+
session = new Session(mockInputs);
438+
439+
await expect(session.pause()).rejects.toThrow(
440+
'qualifier not specified, please specify --qualifier',
441+
);
442+
});
443+
});
444+
445+
describe('resume', () => {
446+
beforeEach(() => {
447+
mockInputs.args = ['resume', '--session-id', 'session-123', '--qualifier', 'LATEST'];
448+
session = new Session(mockInputs);
449+
});
450+
451+
it('should resume session successfully', async () => {
452+
const mockResult = {
453+
sessionId: 'session-123',
454+
qualifier: 'LATEST',
455+
sessionStatus: 'Active',
456+
};
457+
458+
mockFcSdk.resumeFunctionSession = jest.fn().mockResolvedValue(mockResult);
459+
460+
const result = await session.resume();
461+
expect(result).toEqual(mockResult);
462+
expect(mockFcSdk.resumeFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
463+
qualifier: 'LATEST',
464+
});
465+
});
466+
467+
it('should resume session with fileSystemOnly when provided', async () => {
468+
const mockResult = {
469+
sessionId: 'session-123',
470+
qualifier: 'LATEST',
471+
sessionStatus: 'Active',
472+
};
473+
474+
mockFcSdk.resumeFunctionSession = jest.fn().mockResolvedValue(mockResult);
475+
mockInputs.args = [
476+
'resume',
477+
'--session-id',
478+
'session-123',
479+
'--qualifier',
480+
'LATEST',
481+
'--file-system-only',
482+
];
483+
session = new Session(mockInputs);
484+
485+
const result = await session.resume();
486+
expect(result).toEqual(mockResult);
487+
expect(mockFcSdk.resumeFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
488+
qualifier: 'LATEST',
489+
fileSystemOnly: true,
490+
});
491+
});
492+
493+
it('should throw error when functionName is not specified', async () => {
494+
delete mockInputs.props.functionName;
495+
mockInputs.args = ['resume', '--session-id', 'session-123', '--qualifier', 'LATEST'];
496+
session = new Session(mockInputs);
497+
498+
await expect(session.resume()).rejects.toThrow(
499+
'functionName not specified, please specify --function-name',
500+
);
501+
});
502+
503+
it('should throw error when sessionId is not specified', async () => {
504+
mockInputs.args = ['resume', '--qualifier', 'LATEST'];
505+
session = new Session(mockInputs);
506+
507+
await expect(session.resume()).rejects.toThrow(
508+
'sessionId not specified, please specify --session-id',
509+
);
510+
});
511+
512+
it('should throw error when qualifier is not specified', async () => {
513+
mockInputs.args = ['resume', '--session-id', 'session-123'];
514+
session = new Session(mockInputs);
515+
516+
await expect(session.resume()).rejects.toThrow(
517+
'qualifier not specified, please specify --qualifier',
518+
);
519+
});
520+
});
521+
392522
describe('update', () => {
393523
beforeEach(() => {
394524
mockInputs.args = [
@@ -477,10 +607,27 @@ describe('Session', () => {
477607
session = new Session(mockInputs);
478608

479609
await expect(session.update()).rejects.toThrow(
480-
'timeout must be a number between 0 and 21600',
610+
'sessionTTLInSeconds must be a number between 0 and 21600',
481611
);
482612
});
483613

614+
it('should update session without timeout fields when not specified', async () => {
615+
const mockResult = {
616+
sessionId: 'session-123',
617+
qualifier: 'LATEST',
618+
};
619+
620+
mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
621+
mockInputs.args = ['update', '--session-id', 'session-123', '--qualifier', 'LATEST'];
622+
session = new Session(mockInputs);
623+
624+
const result = await session.update();
625+
expect(result).toEqual(mockResult);
626+
expect(mockFcSdk.updateFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
627+
qualifier: 'LATEST',
628+
});
629+
});
630+
484631
it('should update session with disableSessionIdReuse when provided', async () => {
485632
const mockResult = {
486633
sessionId: 'session-123',
@@ -514,6 +661,137 @@ describe('Session', () => {
514661
disableSessionIdReuse: true,
515662
});
516663
});
664+
665+
it('should update session with nasConfig when provided', async () => {
666+
const mockResult = {
667+
sessionId: 'session-123',
668+
qualifier: 'LATEST',
669+
sessionTTLInSeconds: 7200,
670+
sessionIdleTimeoutInSeconds: 3600,
671+
};
672+
673+
mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
674+
mockInputs.args = [
675+
'update',
676+
'--session-id',
677+
'session-123',
678+
'--qualifier',
679+
'LATEST',
680+
'--session-ttl-in-seconds',
681+
'7200',
682+
'--session-idle-timeout-in-seconds',
683+
'3600',
684+
'--nas-config',
685+
'{"userId":1000,"groupId":1000,"mountPoints":[{"serverAddr":"nas-server-addr","mountDir":"/mnt/nas","enableTLS":true}]}',
686+
];
687+
session = new Session(mockInputs);
688+
689+
const result = await session.update();
690+
expect(result).toEqual(mockResult);
691+
expect(mockFcSdk.updateFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
692+
qualifier: 'LATEST',
693+
sessionTTLInSeconds: 7200,
694+
sessionIdleTimeoutInSeconds: 3600,
695+
nasConfig: {
696+
userId: 1000,
697+
groupId: 1000,
698+
mountPoints: [
699+
{
700+
serverAddr: 'nas-server-addr',
701+
mountDir: '/mnt/nas',
702+
enableTLS: true,
703+
},
704+
],
705+
},
706+
});
707+
});
708+
709+
it('should update session with ossMountConfig when provided', async () => {
710+
const mockResult = {
711+
sessionId: 'session-123',
712+
qualifier: 'LATEST',
713+
sessionTTLInSeconds: 7200,
714+
sessionIdleTimeoutInSeconds: 3600,
715+
};
716+
717+
mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
718+
mockInputs.args = [
719+
'update',
720+
'--session-id',
721+
'session-123',
722+
'--qualifier',
723+
'LATEST',
724+
'--session-ttl-in-seconds',
725+
'7200',
726+
'--session-idle-timeout-in-seconds',
727+
'3600',
728+
'--oss-mount-config',
729+
'{"mountPoints":[{"bucketName":"test-bucket","bucketPath":"cn-hangzhou","mountDir":"/mnt/oss","readOnly":false}]}',
730+
];
731+
session = new Session(mockInputs);
732+
733+
const result = await session.update();
734+
expect(result).toEqual(mockResult);
735+
expect(mockFcSdk.updateFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
736+
qualifier: 'LATEST',
737+
sessionTTLInSeconds: 7200,
738+
sessionIdleTimeoutInSeconds: 3600,
739+
ossMountConfig: {
740+
mountPoints: [
741+
{
742+
bucketName: 'test-bucket',
743+
bucketPath: 'cn-hangzhou',
744+
mountDir: '/mnt/oss',
745+
readOnly: false,
746+
},
747+
],
748+
},
749+
});
750+
});
751+
752+
it('should update session with polarFsConfig when provided', async () => {
753+
const mockResult = {
754+
sessionId: 'session-123',
755+
qualifier: 'LATEST',
756+
sessionTTLInSeconds: 7200,
757+
sessionIdleTimeoutInSeconds: 3600,
758+
};
759+
760+
mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
761+
mockInputs.args = [
762+
'update',
763+
'--session-id',
764+
'session-123',
765+
'--qualifier',
766+
'LATEST',
767+
'--session-ttl-in-seconds',
768+
'7200',
769+
'--session-idle-timeout-in-seconds',
770+
'3600',
771+
'--polar-fs-config',
772+
'{"userId":1000,"groupId":1000,"mountPoints":[{"instanceId":"pfs-test","mountDir":"/mnt/polar","remoteDir":"/"}]}',
773+
];
774+
session = new Session(mockInputs);
775+
776+
const result = await session.update();
777+
expect(result).toEqual(mockResult);
778+
expect(mockFcSdk.updateFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
779+
qualifier: 'LATEST',
780+
sessionTTLInSeconds: 7200,
781+
sessionIdleTimeoutInSeconds: 3600,
782+
polarFsConfig: {
783+
userId: 1000,
784+
groupId: 1000,
785+
mountPoints: [
786+
{
787+
instanceId: 'pfs-test',
788+
mountDir: '/mnt/polar',
789+
remoteDir: '/',
790+
},
791+
],
792+
},
793+
});
794+
});
517795
});
518796

519797
describe('list', () => {

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"dependencies": {
2525
"@alicloud/devs20230714": "^2.5.0",
2626
"@alicloud/fc2": "^2.6.6",
27-
"@alicloud/fc20230330": "4.6.8",
27+
"@alicloud/fc20230330": "4.7.4",
2828
"@alicloud/pop-core": "^1.8.0",
2929
"@serverless-cd/srm-aliyun-oss": "^0.0.1-beta.8",
3030
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",

0 commit comments

Comments
 (0)