Skip to content

Commit a6a7437

Browse files
committed
fix(scf): support installDependency config
1 parent cfef151 commit a6a7437

File tree

4 files changed

+27
-131
lines changed

4 files changed

+27
-131
lines changed

__tests__/scf.sp.test.ts

Lines changed: 22 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Scf - singapore', () => {
77
SecretId: process.env.TENCENT_SECRET_ID,
88
SecretKey: process.env.TENCENT_SECRET_KEY,
99
};
10-
const scf = new Scf(credentials, 'ap-singapore');
10+
const scf = new Scf(credentials, 'ap-guangzhou');
1111

1212
const triggers = {
1313
apigw: {
@@ -41,15 +41,15 @@ describe('Scf - singapore', () => {
4141
// name: `serverless-test-${Date.now()}`,
4242
name: `serverless-test-fixed`,
4343
code: {
44-
bucket: 'test-singapore',
45-
object: 'express_code.zip',
44+
bucket: process.env.BUCKET,
45+
object: 'express_code_pure.zip',
4646
},
4747
namespace: 'test',
4848
role: 'SCF_QcsRole',
4949
handler: 'sl_handler.handler',
5050
runtime: 'Nodejs12.16',
51-
region: 'ap-singapore',
52-
description: 'Created by Serverless Framework',
51+
region: 'ap-guangzhou',
52+
description: 'Created by Serverless',
5353
memorySize: 256,
5454
timeout: 20,
5555
tags: {
@@ -61,143 +61,34 @@ describe('Scf - singapore', () => {
6161
},
6262
},
6363
events,
64+
installDependency: true,
6465
};
6566

6667
let outputs;
6768

6869
test('should deploy SCF success', async () => {
6970
await sleep(3000);
7071
outputs = await scf.deploy(inputs);
71-
expect(outputs).toEqual({
72-
Qualifier: '$LATEST',
73-
Description: 'Created by Serverless Framework',
74-
Timeout: inputs.timeout,
75-
InitTimeout: expect.any(Number),
76-
MemorySize: inputs.memorySize,
77-
Runtime: inputs.runtime,
78-
VpcConfig: { VpcId: '', SubnetId: '' },
79-
Environment: {
80-
Variables: [
81-
{
82-
Key: 'TEST',
83-
Value: 'value',
84-
},
85-
],
86-
},
87-
Handler: inputs.handler,
88-
AsyncRunEnable: 'FALSE',
89-
LogType: expect.any(String),
90-
TraceEnable: 'FALSE',
91-
UseGpu: 'FALSE',
92-
Role: inputs.role,
93-
CodeSize: 0,
94-
FunctionVersion: '$LATEST',
95-
FunctionName: inputs.name,
96-
Namespace: 'test',
97-
InstallDependency: 'FALSE',
98-
Status: 'Active',
99-
AvailableStatus: 'Available',
100-
StatusDesc: expect.any(String),
101-
FunctionId: expect.stringContaining('lam-'),
102-
L5Enable: 'FALSE',
103-
EipConfig: { EipFixed: 'FALSE', Eips: expect.any(Array) },
104-
ModTime: expect.any(String),
105-
AddTime: expect.any(String),
106-
Layers: [],
107-
DeadLetterConfig: { Type: '', Name: '', FilterType: '' },
108-
OnsEnable: 'FALSE',
109-
PublicNetConfig: {
110-
PublicNetStatus: 'ENABLE',
111-
EipConfig: { EipStatus: 'DISABLE', EipAddress: expect.any(Array) },
112-
},
113-
Triggers: expect.any(Array),
114-
ClsLogsetId: expect.any(String),
115-
ClsTopicId: expect.any(String),
116-
CodeInfo: '',
117-
CodeResult: 'success',
118-
CodeError: '',
119-
ErrNo: 0,
120-
Tags: [
121-
{
122-
Key: 'test',
123-
Value: 'test',
124-
},
125-
],
126-
AccessInfo: { Host: '', Vip: '' },
127-
Type: 'Event',
128-
CfsConfig: {
129-
CfsInsList: [],
130-
},
131-
StatusReasons: [],
132-
RequestId: expect.any(String),
133-
});
72+
expect(outputs.FunctionName).toBe(inputs.name);
73+
expect(outputs.Qualifier).toBe('$LATEST');
74+
expect(outputs.Description).toBe('Created by Serverless');
75+
expect(outputs.Timeout).toBe(inputs.timeout);
76+
expect(outputs.MemorySize).toBe(inputs.memorySize);
77+
expect(outputs.Runtime).toBe(inputs.runtime);
78+
expect(outputs.InstallDependency).toBe('TRUE');
79+
expect(outputs.Role).toBe(inputs.role);
13480
});
13581
test('should update SCF success', async () => {
13682
await sleep(3000);
13783
outputs = await scf.deploy(inputs);
138-
expect(outputs).toEqual({
139-
Qualifier: '$LATEST',
140-
Description: 'Created by Serverless Framework',
141-
Timeout: inputs.timeout,
142-
InitTimeout: expect.any(Number),
143-
MemorySize: inputs.memorySize,
144-
Runtime: inputs.runtime,
145-
VpcConfig: { VpcId: '', SubnetId: '' },
146-
Environment: {
147-
Variables: [
148-
{
149-
Key: 'TEST',
150-
Value: 'value',
151-
},
152-
],
153-
},
154-
Handler: inputs.handler,
155-
AsyncRunEnable: 'FALSE',
156-
LogType: expect.any(String),
157-
TraceEnable: 'FALSE',
158-
UseGpu: 'FALSE',
159-
Role: inputs.role,
160-
CodeSize: 0,
161-
FunctionVersion: '$LATEST',
162-
FunctionName: inputs.name,
163-
Namespace: 'test',
164-
InstallDependency: 'FALSE',
165-
Status: 'Active',
166-
AvailableStatus: 'Available',
167-
StatusDesc: expect.any(String),
168-
FunctionId: expect.stringContaining('lam-'),
169-
L5Enable: 'FALSE',
170-
EipConfig: { EipFixed: 'FALSE', Eips: expect.any(Array) },
171-
ModTime: expect.any(String),
172-
AddTime: expect.any(String),
173-
Layers: [],
174-
DeadLetterConfig: { Type: '', Name: '', FilterType: '' },
175-
OnsEnable: 'FALSE',
176-
PublicNetConfig: {
177-
PublicNetStatus: 'ENABLE',
178-
EipConfig: { EipStatus: 'DISABLE', EipAddress: expect.any(Array) },
179-
},
180-
Triggers: expect.any(Array),
181-
ClsLogsetId: expect.any(String),
182-
ClsTopicId: expect.any(String),
183-
CodeInfo: '',
184-
CodeResult: 'success',
185-
CodeError: '',
186-
ErrNo: 0,
187-
Tags: [
188-
{
189-
Key: 'test',
190-
Value: 'test',
191-
},
192-
],
193-
AccessInfo: { Host: '', Vip: '' },
194-
Type: 'Event',
195-
CfsConfig: {
196-
CfsInsList: [],
197-
},
198-
StatusReasons: [],
199-
RequestId: expect.any(String),
200-
});
84+
expect(outputs.FunctionName).toBe(inputs.name);
85+
expect(outputs.Qualifier).toBe('$LATEST');
86+
expect(outputs.Description).toBe('Created by Serverless');
87+
expect(outputs.Timeout).toBe(inputs.timeout);
88+
expect(outputs.MemorySize).toBe(inputs.memorySize);
89+
expect(outputs.Runtime).toBe(inputs.runtime);
90+
expect(outputs.InstallDependency).toBe('TRUE');
91+
expect(outputs.Role).toBe(inputs.role);
20192
});
20293
test('should remove Scf success', async () => {
20394
const res = await scf.remove({

src/modules/scf/entities/scf.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export default class ScfEntity extends BaseEntity {
150150
CosBucketName: functionInputs.Code?.CosBucketName,
151151
CosObjectName: functionInputs.Code?.CosObjectName,
152152
Namespace: inputs.namespace || funcInfo.Namespace,
153+
InstallDependency: functionInputs.InstallDependency,
153154
};
154155
await this.request(reqParams);
155156
return true;
@@ -179,6 +180,7 @@ export default class ScfEntity extends BaseEntity {
179180
delete reqInputs.Code;
180181
delete reqInputs.CodeSource;
181182
delete reqInputs.AsyncRunEnable;
183+
delete reqInputs.InstallDependency;
182184

183185
// +++++++++++++++++++++++
184186
// FIXME: 以下是函数绑定层逻辑,当函数有一个层,更新的时候想删除,需要传递参数 Layers 不能为空,必须包含特殊元素:{ LayerName: '', LayerVersion: 0 }

src/modules/scf/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export interface ScfCreateFunctionInputs {
139139

140140
asyncRunEnable?: undefined | boolean;
141141
traceEnable?: undefined | boolean;
142+
installDependency?: undefined | boolean;
142143
}
143144

144145
export interface ScfUpdateAliasTrafficInputs {

src/modules/scf/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const formatInputs = (region: RegionType, inputs: ScfCreateFunctionInputs
4545
};
4646
AsyncRunEnable?: 'TRUE' | 'FALSE';
4747
TraceEnable?: 'TRUE' | 'FALSE';
48+
InstallDependency?: 'TRUE' | 'FALSE';
4849
} = {
4950
FunctionName: inputs.name,
5051
CodeSource: 'Cos',
@@ -65,6 +66,7 @@ export const formatInputs = (region: RegionType, inputs: ScfCreateFunctionInputs
6566
},
6667
},
6768
L5Enable: inputs.l5Enable === true ? 'TRUE' : 'FALSE',
69+
InstallDependency: inputs.installDependency === true ? 'TRUE' : 'FALSE',
6870
};
6971

7072
// 非必须参数

0 commit comments

Comments
 (0)