|
| 1 | +import { sleep } from '@ygkit/request'; |
| 2 | +import { CreateClbTriggerOutput } from './../../src/modules/triggers/interface/clb'; |
| 3 | +import { ClbTriggerInputsParams } from '../../src/modules/triggers/interface'; |
| 4 | +import { Scf } from '../../src'; |
| 5 | +import ClbTrigger from '../../src/modules/triggers/clb'; |
| 6 | + |
| 7 | +describe('Clb Trigger', () => { |
| 8 | + const credentials = { |
| 9 | + SecretId: process.env.TENCENT_SECRET_ID, |
| 10 | + SecretKey: process.env.TENCENT_SECRET_KEY, |
| 11 | + }; |
| 12 | + const client = new ClbTrigger({ credentials, region: process.env.REGION }); |
| 13 | + const scfClient = new Scf(credentials, process.env.REGION); |
| 14 | + |
| 15 | + const data: ClbTriggerInputsParams = { |
| 16 | + qualifier: '$DEFAULT', |
| 17 | + loadBalanceId: 'lb-l6golr1k', |
| 18 | + protocol: 'HTTP', |
| 19 | + domain: '81.71.86.84', |
| 20 | + port: 80, |
| 21 | + url: '/trigger-test', |
| 22 | + weight: 20, |
| 23 | + }; |
| 24 | + |
| 25 | + const functionName = 'serverless-unit-test'; |
| 26 | + const namespace = 'default'; |
| 27 | + let output: CreateClbTriggerOutput; |
| 28 | + |
| 29 | + test('get listeners', async () => { |
| 30 | + const res = await client.clb.getListenerList(data.loadBalanceId); |
| 31 | + expect(res.length).toBe(1); |
| 32 | + }); |
| 33 | + |
| 34 | + test('create clb trigger', async () => { |
| 35 | + output = await client.create({ |
| 36 | + inputs: { |
| 37 | + namespace: namespace, |
| 38 | + functionName: functionName, |
| 39 | + parameters: data, |
| 40 | + }, |
| 41 | + }); |
| 42 | + |
| 43 | + expect(output).toEqual({ |
| 44 | + listenerId: expect.stringContaining('lbl-'), |
| 45 | + locationId: expect.stringContaining('loc-'), |
| 46 | + namespace: namespace, |
| 47 | + functionName: functionName, |
| 48 | + qualifier: '$DEFAULT', |
| 49 | + ...data, |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + test('delete clb trigger', async () => { |
| 54 | + const { Triggers = [] } = await scfClient.request({ |
| 55 | + Action: 'ListTriggers', |
| 56 | + Namespace: namespace, |
| 57 | + FunctionName: functionName, |
| 58 | + Limit: 100, |
| 59 | + }); |
| 60 | + const [exist] = Triggers.filter((item) => { |
| 61 | + const { ResourceId } = item; |
| 62 | + |
| 63 | + if (ResourceId.indexOf(`${output.loadBalanceId}/${output.listenerId}/${output.locationId}`)) { |
| 64 | + return true; |
| 65 | + } |
| 66 | + return false; |
| 67 | + }); |
| 68 | + |
| 69 | + const res = await client.delete({ |
| 70 | + scf: scfClient, |
| 71 | + inputs: { |
| 72 | + namespace: namespace, |
| 73 | + functionName: functionName, |
| 74 | + triggerDesc: exist.TriggerDesc, |
| 75 | + triggerName: exist.TriggerName, |
| 76 | + qualifier: exist.Qualifier, |
| 77 | + }, |
| 78 | + }); |
| 79 | + expect(res).toEqual({ requestId: expect.any(String), success: true }); |
| 80 | + }); |
| 81 | + |
| 82 | + test('delete clb rule', async () => { |
| 83 | + await sleep(3000); |
| 84 | + const res = await client.clb.deleteRule({ |
| 85 | + loadBalanceId: output.loadBalanceId, |
| 86 | + listenerId: output.listenerId, |
| 87 | + locationId: output.locationId, |
| 88 | + }); |
| 89 | + expect(res).toBe(true); |
| 90 | + }); |
| 91 | +}); |
0 commit comments