|
1 | | -const CosUtils = require('./index'); |
| 1 | +const Client = require('./index'); |
2 | 2 |
|
3 | | -class ClientTest { |
4 | | - async cosTest() { |
5 | | - const APP_ID = '1251556596'; |
6 | | - const bucketName = 'test-bucket'; |
7 | | - const cos = new CosUtils({ |
8 | | - SecretId: '', |
9 | | - SecretKey: '', |
10 | | - }); |
11 | | - const cosDemo = { |
12 | | - bucket: `${bucketName}-${APP_ID}`, |
13 | | - force: true, |
14 | | - acl: { |
15 | | - permissions: 'private', |
16 | | - }, |
17 | | - tags: [ |
18 | | - { |
19 | | - key: 'test', |
20 | | - value: 'abcd', |
21 | | - }, |
22 | | - ], |
23 | | - rules: [ |
24 | | - { |
25 | | - status: 'Enabled', |
26 | | - id: 'deleteObject', |
27 | | - filter: '', |
28 | | - expiration: { days: '10' }, |
29 | | - abortIncompleteMultipartUpload: { daysAfterInitiation: '10' }, |
30 | | - }, |
31 | | - ], |
32 | | - }; |
33 | | - const result = await cos.deploy(cosDemo); |
34 | | - console.log(JSON.stringify(result)); |
35 | | - console.log(result); |
| 3 | +async function runTest() { |
| 4 | + const APP_ID = '1251556596'; |
| 5 | + const bucketName = 'test-bucket'; |
| 6 | + const cos = new Client({ |
| 7 | + SecretId: '', |
| 8 | + SecretKey: '', |
| 9 | + }); |
| 10 | + const inputs = { |
| 11 | + bucket: `${bucketName}-${APP_ID}`, |
| 12 | + force: true, |
| 13 | + acl: { |
| 14 | + permissions: 'private', |
| 15 | + }, |
| 16 | + tags: [ |
| 17 | + { |
| 18 | + key: 'test', |
| 19 | + value: 'abcd', |
| 20 | + }, |
| 21 | + ], |
| 22 | + rules: [ |
| 23 | + { |
| 24 | + status: 'Enabled', |
| 25 | + id: 'deleteObject', |
| 26 | + filter: '', |
| 27 | + expiration: { days: '10' }, |
| 28 | + abortIncompleteMultipartUpload: { daysAfterInitiation: '10' }, |
| 29 | + }, |
| 30 | + ], |
| 31 | + }; |
| 32 | + const result = await cos.deploy(inputs); |
| 33 | + console.log(result); |
36 | 34 |
|
| 35 | + await cos.upload({ |
| 36 | + bucket: `${bucketName}-${APP_ID}`, |
| 37 | + dir: '../../utils/', |
| 38 | + }); |
37 | 39 |
|
38 | | - await cos.upload({ |
39 | | - bucket: `${bucketName}-${APP_ID}`, |
40 | | - dir: '../../utils/', |
41 | | - }); |
| 40 | + await cos.remove({ |
| 41 | + bucket: `${bucketName}-${APP_ID}`, |
| 42 | + }); |
42 | 43 |
|
43 | | - await cos.remove({ |
44 | | - bucket: `${bucketName}-${APP_ID}`, |
45 | | - }); |
46 | | - |
47 | | - } |
48 | 44 | } |
49 | 45 |
|
50 | | -new ClientTest().cosTest(); |
| 46 | +runTest(); |
| 47 | + |
| 48 | +process.on('unhandledRejection', (e) => { |
| 49 | + console.log(e); |
| 50 | +}); |
| 51 | + |
0 commit comments