Skip to content

Commit 6a58dde

Browse files
committed
fix(scf): supoort traceEnable
1 parent 4d4f517 commit 6a58dde

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

__tests__/scf.test.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ScfDeployInputs } from './../src/modules/scf/interface';
22
import { sleep } from '@ygkit/request';
33
import { Scf, Cfs, Layer } from '../src';
44

5-
// FIXME: skip mps test
65
describe('Scf', () => {
76
const credentials = {
87
SecretId: process.env.TENCENT_SECRET_ID,
@@ -90,7 +89,8 @@ describe('Scf', () => {
9089
const events = Object.entries(triggers).map(([, value]) => value);
9190

9291
const inputs: ScfDeployInputs = {
93-
name: `serverless-test-${Date.now()}`,
92+
// name: `serverless-test-${Date.now()}`,
93+
name: `serverless-test-fixed`,
9494
code: {
9595
bucket: process.env.BUCKET,
9696
object: 'express_code.zip',
@@ -168,7 +168,7 @@ describe('Scf', () => {
168168
done();
169169
});
170170

171-
test('should deploy SCF success', async () => {
171+
test('deploy', async () => {
172172
await sleep(3000);
173173
outputs = await scf.deploy(inputs);
174174
expect(outputs).toEqual({
@@ -353,7 +353,7 @@ describe('Scf', () => {
353353
},
354354
]);
355355
});
356-
test('should update SCF success', async () => {
356+
test('update', async () => {
357357
await sleep(3000);
358358
outputs = await scf.deploy(inputs);
359359
expect(outputs).toEqual({
@@ -538,7 +538,7 @@ describe('Scf', () => {
538538
},
539539
]);
540540
});
541-
test('should invoke Scf success', async () => {
541+
test('invoke', async () => {
542542
const res = await scf.invoke({
543543
namespace: inputs.namespace,
544544
functionName: inputs.name,
@@ -557,7 +557,23 @@ describe('Scf', () => {
557557
RequestId: expect.any(String),
558558
});
559559
});
560-
test('should remove Scf success', async () => {
560+
test('remove', async () => {
561+
const res = await scf.remove({
562+
functionName: inputs.name,
563+
...outputs,
564+
});
565+
expect(res).toEqual(true);
566+
});
567+
test('[asyncRunEnable and traceEnable] create', async () => {
568+
await sleep(3000);
569+
inputs.asyncRunEnable = true;
570+
inputs.traceEnable = true;
571+
outputs = await scf.deploy(inputs);
572+
573+
expect(outputs.AsyncRunEnable).toBe('TRUE');
574+
expect(outputs.TraceEnable).toBe('TRUE');
575+
});
576+
test('[asyncRunEnable and traceEnable] remove', async () => {
561577
const res = await scf.remove({
562578
functionName: inputs.name,
563579
...outputs,

src/modules/scf/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export interface ScfCreateFunctionInputs {
135135
userId?: string;
136136
}[];
137137

138-
asyncRunEnable?: {};
138+
asyncRunEnable?: undefined | boolean;
139+
traceEnable?: undefined | boolean;
139140
}
140141

141142
export interface ScfUpdateAliasTrafficInputs {

src/modules/scf/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const formatInputs = (region: RegionType, inputs: ScfCreateFunctionInputs
4444
}[];
4545
};
4646
AsyncRunEnable?: 'TRUE' | 'FALSE';
47+
TraceEnable?: 'TRUE' | 'FALSE';
4748
} = {
4849
FunctionName: inputs.name,
4950
CodeSource: 'Cos',
@@ -143,6 +144,12 @@ export const formatInputs = (region: RegionType, inputs: ScfCreateFunctionInputs
143144
if (inputs.asyncRunEnable !== undefined) {
144145
functionInputs.AsyncRunEnable = inputs.asyncRunEnable === true ? 'TRUE' : 'FALSE';
145146
}
147+
// 只有配置 asyncRunEnable 为 true 时,才能配置 traceEnable 为 true
148+
if (inputs.traceEnable === true && functionInputs.AsyncRunEnable === 'TRUE') {
149+
functionInputs.TraceEnable = 'TRUE';
150+
} else {
151+
functionInputs.TraceEnable = 'FALSE';
152+
}
146153

147154
return functionInputs;
148155
};

0 commit comments

Comments
 (0)