Skip to content

Commit a376529

Browse files
authored
fix: flush more than 1000 files bucket (#35)
* fix: flush more than 1000 files bucket * test: update
1 parent b4a4da8 commit a376529

File tree

9 files changed

+44
-34
lines changed

9 files changed

+44
-34
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ jobs:
4141
- name: Running integration tests
4242
run: npm run test
4343
env:
44+
SERVERLESS_PLATFORM_VENDOR: tencent
45+
GLOBAL_ACCELERATOR_NA: true
46+
TENCENT_APP_ID: ${{ secrets.TENCENT_APP_ID }}
4447
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
4548
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

__tests__/index.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ const path = require('path')
22
const axios = require('axios')
33
const { generateId, getServerlessSdk } = require('./lib/utils')
44

5+
const appId = process.env.TENCENT_APP_ID
6+
const credentials = {
7+
tencent: {
8+
SecretId: process.env.TENCENT_SECRET_ID,
9+
SecretKey: process.env.TENCENT_SECRET_KEY
10+
}
11+
}
12+
513
const instanceYaml = {
614
org: 'orgDemo',
715
app: 'appDemo',
@@ -19,14 +27,7 @@ const instanceYaml = {
1927
}
2028
}
2129

22-
const credentials = {
23-
tencent: {
24-
SecretId: process.env.TENCENT_SECRET_ID,
25-
SecretKey: process.env.TENCENT_SECRET_KEY,
26-
}
27-
}
28-
29-
const sdk = getServerlessSdk(instanceYaml.org)
30+
const sdk = getServerlessSdk(instanceYaml.org, appId)
3031

3132
it('should deploy success', async () => {
3233
const instance = await sdk.deploy(instanceYaml, credentials)
@@ -37,14 +38,14 @@ it('should deploy success', async () => {
3738
expect(instance.outputs.region).toEqual(instanceYaml.inputs.region)
3839
// exist page
3940
const { data } = await axios.get(instance.outputs.website)
40-
expect(data).toContain('Serverless Framework');
41+
expect(data).toContain('Serverless');
4142

4243
// not exist page
4344
try {
4445
await axios.get(`${instance.outputs.website}/error.html`)
4546
} catch (e) {
4647
const { response } = e
47-
expect(response.data).toContain('Serverless Framework');
48+
expect(response.data).toContain('Serverless');
4849
expect(response.status).toBe(404)
4950
}
5051
})
@@ -59,10 +60,10 @@ it('should update success', async () => {
5960
expect(instance.outputs.region).toEqual(instanceYaml.inputs.region)
6061
// exist page
6162
const { data } = await axios.get(instance.outputs.website)
62-
expect(data).toContain('Serverless Framework');
63+
expect(data).toContain('Serverless');
6364
// not exist page
6465
const res = await axios.get(`${instance.outputs.website}/error.html`)
65-
expect(res.data).toContain('Serverless Framework');
66+
expect(res.data).toContain('Serverless');
6667
expect(res.status).toBe(200)
6768
})
6869

__tests__/lib/utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const { ServerlessSDK } = require('@serverless/platform-client-china')
22

3-
/*
4-
* Generate random id
5-
*/
63
const generateId = () =>
74
Math.random()
85
.toString(36)
96
.substring(6)
107

11-
/*
12-
* Initializes and returns an instance of the serverless sdk
13-
* @param ${string} orgName - the serverless org name.
14-
*/
15-
const getServerlessSdk = (orgName) => {
8+
function sleep(ms) {
9+
return new Promise((resolve) => {
10+
setTimeout(() => {
11+
resolve(true)
12+
}, ms)
13+
})
14+
}
15+
16+
function getServerlessSdk(orgName, orgUid) {
1617
const sdk = new ServerlessSDK({
1718
context: {
19+
orgUid,
1820
orgName
1921
}
2022
})
2123
return sdk
2224
}
2325

24-
module.exports = { generateId, getServerlessSdk }
26+
module.exports = { sleep, generateId, getServerlessSdk }

example/src/index.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Serverless Component - Website</title>
6+
<meta name="description" content="Serverless Website 应用" />
7+
<meta name="keywords" content="website,serverless,无服务" />
8+
<title>Serverless - Website</title>
79
<style lang="css">
810
h1 {
911
text-align: center;
@@ -14,8 +16,12 @@
1416
</head>
1517
<body>
1618
<h1>
17-
Welcome to website created by
18-
<a href="https://serverlesscloud.cn/">Serverless Framework.</a>
19+
欢迎访问静态网站
20+
<br />
21+
<a href="https://cloud.tencent.com/product/sls" target="_blank" rel="noopener noreferrer">
22+
腾讯云 Serverless
23+
</a>
24+
为您提供服务
1925
</h1>
2026
</body>
2127
</html>

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = {
66
silent: false,
77
testTimeout: 300000,
88
testEnvironment: 'node',
9-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$',
9+
testRegex: '/__tests__/.*\\.(test|spec)\\.(js|ts)$',
1010
testPathIgnorePatterns: ['/node_modules/', '/__tests__/lib/'],
1111
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
1212
}

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
},
2626
"lint-staged": {
2727
"**/*.{js,ts,tsx}": [
28-
"npm run lint:fix",
29-
"git add ."
28+
"npm run lint:fix"
3029
],
3130
"**/*.{css,html,js,json,md,yaml,yml}": [
32-
"npm run prettier:fix",
33-
"git add ."
31+
"npm run prettier:fix"
3432
]
3533
},
3634
"author": "Tencent Cloud, Inc.",
@@ -44,7 +42,7 @@
4442
"@semantic-release/git": "^9.0.0",
4543
"@semantic-release/npm": "^7.0.4",
4644
"@semantic-release/release-notes-generator": "^9.0.1",
47-
"@serverless/platform-client-china": "^2.0.9",
45+
"@serverless/platform-client-china": "^2.1.9",
4846
"@ygkit/secure": "0.0.3",
4947
"axios": "^0.21.0",
5048
"babel-eslint": "^10.1.0",

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: website
2-
version: 0.1.2
2+
version: 0.1.3
33
author: 'Tencent Cloud, Inc.'
44
org: 'Tencent Cloud, Inc.'
55
description: Deploy a static website on Tencent Cloud.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"download": "^8.0.0",
4-
"tencent-component-toolkit": "^1.20.5",
4+
"tencent-component-toolkit": "^2.5.3",
55
"type": "^2.1.0"
66
}
77
}

src/serverless.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Component } = require('@serverless/core')
22
const { Cos, Cdn } = require('tencent-component-toolkit')
3-
const { TypeError } = require('tencent-component-toolkit/src/utils/error')
3+
const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error')
44
const CONFIGS = require('./config')
55
const { prepareInputs } = require('./utils')
66

@@ -9,7 +9,7 @@ class ServerlessComponent extends Component {
99
const { tmpSecrets } = this.credentials.tencent
1010

1111
if (!tmpSecrets || !tmpSecrets.TmpSecretId) {
12-
throw new TypeError(
12+
throw new ApiTypeError(
1313
'CREDENTIAL',
1414
'Cannot get secretId/Key, your account could be sub-account and does not have the access to use SLS_QcsRole, please make sure the role exists first, then visit https://cloud.tencent.com/document/product/1154/43006, follow the instructions to bind the role to your account.'
1515
)

0 commit comments

Comments
 (0)