|
1 | | -import { DeployDashboardInputs } from '../../src/modules/cls/interface'; |
2 | 1 | import { Cls } from '../../src'; |
| 2 | +import { |
| 3 | + DashboardChartType, |
| 4 | + DeployDashboardInputs, |
| 5 | + DeployDashChartInputs, |
| 6 | +} from '../../src/modules/cls/dashboard'; |
3 | 7 |
|
4 | 8 | // TODO: 添加更多的图形测试用例,目前 CLS 产品并未相关说明文档 |
5 | 9 | describe('Cls dashboard', () => { |
6 | 10 | const credentials = { |
7 | 11 | SecretId: process.env.TENCENT_SECRET_ID, |
8 | 12 | SecretKey: process.env.TENCENT_SECRET_KEY, |
9 | 13 | }; |
10 | | - const clsConfig = { |
| 14 | + const logsetConfig = { |
| 15 | + region: process.env.REGION, |
11 | 16 | logsetId: '5681feab-fae1-4a50-b41b-fb93d565d1fc', |
12 | 17 | topicId: 'c429f9ca-8229-4cef-9d63-dd9ad6189f4c', |
13 | 18 | }; |
14 | 19 | // * | select SCF_StartTime as time, max(SCF_MemUsage) / 1000000 as memory group by SCF_StartTime |
15 | | - const chart1Config = { |
16 | | - id: 'chart-d0a90626-0a73-466c-8a94-2f5bdc597abd', |
| 20 | + const chart1Config: DeployDashChartInputs = { |
17 | 21 | title: 'Request URL Time', |
18 | | - type: 'bar', |
| 22 | + type: 'bar' as DashboardChartType, |
19 | 23 | query: '* | select url,request_time', |
20 | | - yAxis: 'request_time', |
21 | | - yAxisUnit: 'ms', |
| 24 | + yAxisKey: 'request_time', |
22 | 25 | aggregateKey: 'url', |
23 | 26 | }; |
24 | | - const chart2Config = { |
25 | | - id: 'chart-ed7a85c7-5327-4763-93c0-b137be676258', |
| 27 | + const chart2Config: DeployDashChartInputs = { |
26 | 28 | title: '4xx Code', |
27 | | - type: 'bar', |
| 29 | + type: 'bar' as DashboardChartType, |
28 | 30 | query: |
29 | 31 | '* | select error_code, count(*) as count where error_code > 400 and error_code < 500 group by error_code', |
30 | | - yAxis: 'count', |
31 | | - yAxisUnit: '', |
| 32 | + yAxisKey: 'count', |
32 | 33 | aggregateKey: 'error_code', |
33 | 34 | }; |
34 | | - const client = new Cls(credentials, process.env.REGION); |
| 35 | + const cls = new Cls(credentials, process.env.REGION); |
35 | 36 |
|
36 | 37 | const inputs: DeployDashboardInputs = { |
37 | | - name: 'serverless-unit-test', |
38 | | - data: JSON.stringify({ |
39 | | - panels: [ |
40 | | - { |
41 | | - id: chart1Config.id, |
42 | | - title: chart1Config.title, |
43 | | - description: null, |
44 | | - gridPos: { x: 0, y: 0, w: 12, h: 8 }, |
45 | | - type: chart1Config.type, |
46 | | - target: { |
47 | | - RegionId: 1, |
48 | | - LogsetId: clsConfig.logsetId, |
49 | | - TopicId: clsConfig.topicId, |
50 | | - Query: chart1Config.query, |
51 | | - ChartAxis: { |
52 | | - xAxisKey: '', |
53 | | - yAxisKeys: [chart1Config.yAxis], |
54 | | - aggregateKey: chart1Config.aggregateKey, |
55 | | - }, |
56 | | - }, |
57 | | - chartConfig: { |
58 | | - orientation: true, |
59 | | - unit: chart1Config.yAxisUnit, |
60 | | - options: { dataLinks: [] }, |
61 | | - legend: { show: false }, |
62 | | - xAxis: { position: 'bottom', axisLabel: {} }, |
63 | | - yAxis: { position: 'top' }, |
64 | | - type: 'basicBar', |
65 | | - staticStyle: 'current', |
66 | | - sort: -1, |
67 | | - decimals: null, |
68 | | - id: chart1Config.id, |
69 | | - }, |
70 | | - fieldConfig: { defaults: {}, overrides: [] }, |
71 | | - }, |
72 | | - { |
73 | | - id: chart2Config.id, |
74 | | - title: chart2Config.title, |
75 | | - description: null, |
76 | | - gridPos: { x: 0, y: 0, w: 12, h: 8 }, |
77 | | - type: chart2Config.type, |
78 | | - target: { |
79 | | - RegionId: 1, |
80 | | - LogsetId: clsConfig.logsetId, |
81 | | - TopicId: clsConfig.topicId, |
82 | | - Query: chart2Config.query, |
83 | | - ChartAxis: { |
84 | | - xAxisKey: '', |
85 | | - yAxisKeys: [chart2Config.yAxis], |
86 | | - aggregateKey: chart2Config.aggregateKey, |
87 | | - }, |
88 | | - }, |
89 | | - chartConfig: { |
90 | | - orientation: true, |
91 | | - unit: chart2Config.yAxisUnit, |
92 | | - options: { dataLinks: [] }, |
93 | | - legend: { show: false }, |
94 | | - xAxis: { position: 'bottom', axisLabel: {} }, |
95 | | - yAxis: { position: 'top' }, |
96 | | - type: 'basicBar', |
97 | | - staticStyle: 'current', |
98 | | - sort: -1, |
99 | | - decimals: null, |
100 | | - id: chart2Config.id, |
101 | | - }, |
102 | | - fieldConfig: { defaults: {}, overrides: [] }, |
103 | | - }, |
104 | | - ], |
105 | | - }), |
| 38 | + name: 'serverless-unit-test-dashboard', |
| 39 | + chartList: [chart1Config, chart2Config], |
106 | 40 | }; |
107 | 41 |
|
108 | 42 | let dashboardId = ''; |
109 | 43 |
|
110 | 44 | test('deploy dashboard', async () => { |
111 | | - const res = await client.deployDashboard(inputs); |
| 45 | + const res = await cls.dashboard.deploy(inputs, logsetConfig); |
112 | 46 | expect(res).toEqual({ |
113 | 47 | id: expect.stringContaining('dashboard-'), |
114 | 48 | name: inputs.name, |
115 | | - data: inputs.data, |
| 49 | + chartList: expect.any(Array), |
116 | 50 | }); |
117 | 51 |
|
118 | 52 | dashboardId = res.id; |
| 53 | + |
| 54 | + console.log({ dashboardId }); |
119 | 55 | }); |
120 | 56 |
|
121 | 57 | test('get dashboard list', async () => { |
122 | | - const res = await client.getDashboardList(); |
| 58 | + const res = await cls.dashboard.getList(); |
123 | 59 | expect(res[0]).toEqual({ |
124 | 60 | createTime: expect.any(String), |
125 | 61 | id: expect.stringContaining('dashboard-'), |
126 | 62 | name: expect.any(String), |
127 | | - data: expect.any(String), |
| 63 | + chartList: expect.any(Array), |
128 | 64 | }); |
129 | 65 | }); |
130 | 66 |
|
131 | 67 | test('get dashboard detail by id', async () => { |
132 | | - const res = await client.getDashboardDetail({ |
| 68 | + console.log({ dashboardId }); |
| 69 | + const res = await cls.dashboard.getDetail({ |
133 | 70 | id: dashboardId, |
134 | 71 | }); |
135 | 72 | expect(res).toEqual({ |
136 | | - createTime: expect.any(String), |
137 | 73 | id: expect.stringContaining('dashboard-'), |
138 | 74 | name: expect.any(String), |
139 | | - data: expect.any(String), |
| 75 | + createTime: expect.any(String), |
| 76 | + chartList: expect.any(Array), |
140 | 77 | }); |
141 | 78 | }); |
142 | 79 |
|
143 | 80 | test('get dashboard detail by name', async () => { |
144 | | - const res = await client.getDashboardDetail({ |
| 81 | + const res = await cls.dashboard.getDetail({ |
145 | 82 | name: inputs.name, |
146 | 83 | }); |
147 | 84 | expect(res).toEqual({ |
148 | 85 | createTime: expect.any(String), |
149 | 86 | id: expect.stringContaining('dashboard-'), |
150 | 87 | name: expect.any(String), |
151 | | - data: expect.any(String), |
| 88 | + chartList: expect.any(Array), |
152 | 89 | }); |
153 | 90 | }); |
154 | 91 |
|
155 | 92 | test('remove dashboard', async () => { |
156 | | - const res = await client.removeDashboard(inputs); |
| 93 | + const res = await cls.dashboard.remove(inputs); |
157 | 94 | expect(res).toEqual(true); |
158 | 95 | }); |
159 | 96 | }); |
0 commit comments