|
| 1 | +import { Monitor } from '../src'; |
| 2 | + |
| 3 | +describe('Monitor', () => { |
| 4 | + const credentials = { |
| 5 | + SecretId: process.env.TENCENT_SECRET_ID, |
| 6 | + SecretKey: process.env.TENCENT_SECRET_KEY, |
| 7 | + }; |
| 8 | + const monitor = new Monitor(credentials, process.env.REGION); |
| 9 | + |
| 10 | + test('get monitor data', async () => { |
| 11 | + const res = await monitor.get({ |
| 12 | + functionName: 'serverless-unit-test', |
| 13 | + metric: 'Invocation', |
| 14 | + }); |
| 15 | + |
| 16 | + expect(res).toEqual({ |
| 17 | + StartTime: expect.any(String), |
| 18 | + EndTime: expect.any(String), |
| 19 | + Period: 60, |
| 20 | + MetricName: 'Invocation', |
| 21 | + DataPoints: [ |
| 22 | + { |
| 23 | + Dimensions: [ |
| 24 | + { Name: 'functionName', Value: 'serverless-unit-test' }, |
| 25 | + { Name: 'namespace', Value: 'default' }, |
| 26 | + ], |
| 27 | + Timestamps: expect.any(Array), |
| 28 | + Values: expect.any(Array), |
| 29 | + }, |
| 30 | + ], |
| 31 | + RequestId: expect.any(String), |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + test('[inverval] get monitor data', async () => { |
| 36 | + const res = await monitor.get({ |
| 37 | + functionName: 'serverless-unit-test', |
| 38 | + metric: 'Invocation', |
| 39 | + interval: 3600, |
| 40 | + }); |
| 41 | + |
| 42 | + expect(res).toEqual({ |
| 43 | + StartTime: expect.any(String), |
| 44 | + EndTime: expect.any(String), |
| 45 | + Period: 60, |
| 46 | + MetricName: 'Invocation', |
| 47 | + DataPoints: [ |
| 48 | + { |
| 49 | + Dimensions: [ |
| 50 | + { Name: 'functionName', Value: 'serverless-unit-test' }, |
| 51 | + { Name: 'namespace', Value: 'default' }, |
| 52 | + ], |
| 53 | + Timestamps: expect.any(Array), |
| 54 | + Values: expect.any(Array), |
| 55 | + }, |
| 56 | + ], |
| 57 | + RequestId: expect.any(String), |
| 58 | + }); |
| 59 | + }); |
| 60 | + test('[period] get monitor data', async () => { |
| 61 | + const res = await monitor.get({ |
| 62 | + functionName: 'serverless-unit-test', |
| 63 | + metric: 'Invocation', |
| 64 | + period: 300, |
| 65 | + }); |
| 66 | + |
| 67 | + expect(res).toEqual({ |
| 68 | + StartTime: expect.any(String), |
| 69 | + EndTime: expect.any(String), |
| 70 | + Period: 300, |
| 71 | + MetricName: 'Invocation', |
| 72 | + DataPoints: [ |
| 73 | + { |
| 74 | + Dimensions: [ |
| 75 | + { Name: 'functionName', Value: 'serverless-unit-test' }, |
| 76 | + { Name: 'namespace', Value: 'default' }, |
| 77 | + ], |
| 78 | + Timestamps: expect.any(Array), |
| 79 | + Values: expect.any(Array), |
| 80 | + }, |
| 81 | + ], |
| 82 | + RequestId: expect.any(String), |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments