From: Laura Flores Date: Wed, 22 Sep 2021 17:55:40 +0000 (+0000) Subject: mgr/dashboard: add unit test for telemetry replacer method X-Git-Tag: v17.1.0~818^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=484126b98836e563144e6908809b61697f0f2286;p=ceph.git mgr/dashboard: add unit test for telemetry replacer method This unit test checks that the "replacer" method in telemetry.component.ts works as it should. The replacer method takes the telemetry report and changes the ranges and values of the 'osd_perf_histograms' field from arrays to strings, thereby making the report more readable in the Dashboard Telemetry Preview. This unit test needs improvement since it currently uses a test report rather than the real one. Signed-off-by: Laura Flores --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts index 08adebbab6b9..2d809cca817d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts @@ -170,6 +170,36 @@ describe('TelemetryComponent', () => { expect(component).toBeTruthy(); }); + it ('should only replace the ranges and values of a JSON object', () => { + var report = component.replacerTest({'ranges': [[null, -1], [0, 511], [512, 1023]], + 'values': [[0,0,0], [0,0,0], [0,0,0]], + 'other': [[0,0,0], [0,0,0], [0,0,0]]}); + report = JSON.parse(report); + + // Ensure that the outer arrays have remained untouched by replacer + expect(Array.isArray(report['ranges']) && Array.isArray(report['values']) && Array.isArray(report['other'])).toBeTruthy() + + if (Array.isArray(report['ranges']) && Array.isArray(report['values']) && Array.isArray(report['other'])) { + var idx; + + // Check that each range in 'ranges' was replaced by a string + for (idx=0; idx { component.onSubmit(); const req = httpTesting.expectOne('api/telemetry'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts index e316f9327d09..17bec010cb75 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts @@ -105,6 +105,10 @@ export class TelemetryComponent extends CdForm implements OnInit { return value; } + replacerTest(report: object) { + return JSON.stringify(report, this.replacer, 2); + } + private createPreviewForm() { const controls = { report: JSON.stringify(this.report, this.replacer, 2),