Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ name: scfdemo # (必填) 创建的实例名称,请修改成您的实例名称
inputs:
name: ${name}-${stage}-${app} #函数名称
src: ./ #代码路径
handler: index.main_handler #入口
type: 'web' # 部署Web函数时需指定该值
handler: index.main_handler #入口(部署非Web函数时生效)
runtime: Nodejs10.15 # 云函数运行时的环境
region: ap-guangzhou # 云函数所在区域
events: # 触发器
Expand All @@ -93,14 +94,16 @@ serverless.yml 文件包含的信息:

inputs 下的参数为组件配置参数。一个最简单 SCF 组件参数配置由以下几部分:

| 参数名 | 说明 |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| name | 云函数名称。由于云函数又是资源 ID,为了保证资源的唯一性,建议采用 `${name}-${stage}-${app}` 变量方式。 |
| src | 代码路径。 |
| handler | 函数处理方法名称 。 |
| runtime | 云函数运行环境,目前支持: Python2.7、Python3.6、Nodejs6.10、Nodejs8.9、Nodejs10.15、Nodejs12.16、PHP5、PHP7、Go1、Java8 和 CustomRuntime。 |
| region | 云函数所在的区域。 |
| events | 触发器。 支持的触发器为:timer、apigw、cos、cmq、ckafka 。 |
| 参数名 | 说明 |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| name | 云函数名称。由于云函数又是资源 ID,为了保证资源的唯一性,建议采用 `${name}-${stage}-${app}` 变量方式。 |
| src | 代码路径。 |
| type | 函数类型,默认为事件函数。支持的类型为:event(事件函数),web(Web 函数)。 |
| handler | 函数处理方法名称 。 |
| entryFile | 函数入口文件名。(函数类型为 web 且无 scf_bootstrap 文件时生效) |
| runtime | 云函数运行环境,目前支持: Python2.7、Python3.6、Nodejs6.10、Nodejs8.9、Nodejs10.15、Nodejs12.16、PHP5、PHP7、Go1、Java8 和 CustomRuntime。 |
| region | 云函数所在的区域。 |
| events | 触发器。 支持的触发器为:timer、apigw、cos、cmq、ckafka 。 |

### 账号权限

Expand Down
91 changes: 91 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,41 @@ describe('Scf', () => {
inputs
}

const webFuncYaml = {
org: appId,
app: 'appDemo',
component: 'scf@dev',
name: `scf-web-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {
name: `scf-web-integration-tests-${generateId()}`,
src: {
src: path.join(__dirname, '../example/web/src'),
exclude: ['.env']
},
type: 'web',
region: 'ap-chengdu',
runtime: 'Nodejs12.16',
events: [
{
apigw: {
parameters: {
protocols: ['http', 'https'],
description: 'The service of Serverless Framework',
environment: 'test',
endpoints: [
{
path: '/',
method: 'ANY'
}
]
}
}
}
]
}
}

const sdk = getServerlessSdk(instanceYaml.org, appId)

let lastVersion = '$LATEST'
Expand Down Expand Up @@ -370,4 +405,60 @@ describe('Scf', () => {

expect(result.instance.instanceStatus).toEqual('inactive')
})

it('deploy web function', async () => {
const instance = await sdk.deploy(webFuncYaml, credentials)

expect(instance).toBeDefined()
expect(instance.instanceName).toEqual(webFuncYaml.name)

const { outputs } = instance
// get src from template by default
expect(outputs.functionName).toEqual(webFuncYaml.inputs.name)
expect(outputs.runtime).toEqual(webFuncYaml.inputs.runtime)
expect(outputs.triggers).toBeDefined()
expect(outputs.triggers.length).toBe(1)

const { triggers } = outputs
const apiTrigger = triggers[0]

expect(apiTrigger).toEqual({
NeedCreate: expect.any(Boolean),
created: expect.any(Boolean),
serviceId: expect.stringContaining('service-'),
serviceName: 'serverless',
subDomain: expect.stringContaining('.cd.apigw.tencentcs.com'),
protocols: 'http&https',
environment: 'test',
url: expect.stringContaining('http'),
apiList: [
{
created: expect.any(Boolean),
path: '/',
method: 'ANY',
apiId: expect.stringContaining('api-'),
apiName: 'index',
authType: 'NONE',
businessType: 'NORMAL',
internalDomain: expect.any(String),
url: expect.stringContaining('http'),
isBase64Encoded: false
}
],
urls: expect.any(Array)
})
})

it('remove web function', async () => {
await sleep(5000)
await sdk.remove(webFuncYaml, credentials)
const result = await sdk.getInstance(
webFuncYaml.org,
webFuncYaml.stage,
webFuncYaml.app,
webFuncYaml.name
)

expect(result.instance.instanceStatus).toEqual('inactive')
})
})
Loading