|  | 
|  | 1 | +import { sleep } from '@ygkit/request'; | 
|  | 2 | +import { Scf } from '../../src'; | 
|  | 3 | +import { ScfDeployInputs } from '../../src/modules/scf/interface'; | 
|  | 4 | + | 
|  | 5 | +describe('Scf', () => { | 
|  | 6 | + const credentials = { | 
|  | 7 | + SecretId: process.env.TENCENT_SECRET_ID, | 
|  | 8 | + SecretKey: process.env.TENCENT_SECRET_KEY, | 
|  | 9 | + }; | 
|  | 10 | + const scf = new Scf(credentials); | 
|  | 11 | + | 
|  | 12 | + const inputs: ScfDeployInputs = { | 
|  | 13 | + name: `serverless-test-${Date.now()}`, | 
|  | 14 | + code: { | 
|  | 15 | + bucket: process.env.BUCKET, | 
|  | 16 | + object: 'express_code.zip', | 
|  | 17 | + }, | 
|  | 18 | + namespace: 'test', | 
|  | 19 | + role: 'SCF_QcsRole', | 
|  | 20 | + handler: 'sl_handler.handler', | 
|  | 21 | + runtime: 'Nodejs12.16', | 
|  | 22 | + region: 'ap-guangzhou', | 
|  | 23 | + description: 'Created by Serverless', | 
|  | 24 | + memorySize: 256, | 
|  | 25 | + timeout: 20, | 
|  | 26 | + tags: { | 
|  | 27 | + test: 'test', | 
|  | 28 | + }, | 
|  | 29 | + environment: { | 
|  | 30 | + variables: { | 
|  | 31 | + TEST: 'value', | 
|  | 32 | + }, | 
|  | 33 | + }, | 
|  | 34 | + }; | 
|  | 35 | + let outputs; | 
|  | 36 | + | 
|  | 37 | + test('[asyncRunEnable and traceEnable] create', async () => { | 
|  | 38 | + await sleep(3000); | 
|  | 39 | + delete inputs.cls; | 
|  | 40 | + inputs.asyncRunEnable = true; | 
|  | 41 | + inputs.traceEnable = true; | 
|  | 42 | + inputs.msgTTL = 3600; | 
|  | 43 | + inputs.retryNum = 0; | 
|  | 44 | + outputs = await scf.deploy(inputs); | 
|  | 45 | + | 
|  | 46 | + const asyncConfig = await scf.scf.getAsyncRetryConfig(inputs, {} as any); | 
|  | 47 | + | 
|  | 48 | + expect(outputs.AsyncRunEnable).toBe('TRUE'); | 
|  | 49 | + expect(outputs.TraceEnable).toBe('TRUE'); | 
|  | 50 | + expect(asyncConfig).toEqual({ | 
|  | 51 | + AsyncTriggerConfig: { | 
|  | 52 | + MsgTTL: 3600, | 
|  | 53 | + RetryConfig: [ | 
|  | 54 | + { ErrorCode: ['default'], RetryNum: 0, RetryInterval: 60 }, | 
|  | 55 | + { ErrorCode: ['432'], RetryNum: -1, RetryInterval: 60 }, | 
|  | 56 | + ], | 
|  | 57 | + }, | 
|  | 58 | + RequestId: expect.any(String), | 
|  | 59 | + }); | 
|  | 60 | + }); | 
|  | 61 | + test('[asyncRunEnable and traceEnable] update', async () => { | 
|  | 62 | + await sleep(3000); | 
|  | 63 | + inputs.asyncRunEnable = true; | 
|  | 64 | + inputs.traceEnable = false; | 
|  | 65 | + outputs = await scf.deploy(inputs); | 
|  | 66 | + | 
|  | 67 | + expect(outputs.AsyncRunEnable).toBe('TRUE'); | 
|  | 68 | + expect(outputs.TraceEnable).toBe('FALSE'); | 
|  | 69 | + }); | 
|  | 70 | + test('[asyncRunEnable and traceEnable] remove', async () => { | 
|  | 71 | + const res = await scf.remove({ | 
|  | 72 | + functionName: inputs.name, | 
|  | 73 | + ...outputs, | 
|  | 74 | + }); | 
|  | 75 | + expect(res).toEqual(true); | 
|  | 76 | + }); | 
|  | 77 | +}); | 
0 commit comments