]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add unit test for telemetry replacer method
authorLaura Flores <lflores@redhat.com>
Wed, 22 Sep 2021 17:55:40 +0000 (17:55 +0000)
committerLaura Flores <lflores@redhat.com>
Wed, 22 Sep 2021 18:49:57 +0000 (18:49 +0000)
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 <lflores@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts

index 08adebbab6b928af660fdcbd3f08bd4080da6b55..2d809cca817df3bfe041d0cdf9c06bd897007e93 100644 (file)
@@ -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<report['ranges'].length; idx++) {
+               expect(typeof report['ranges'][idx] === 'string').toBeTruthy();
+        }
+
+       // Check that each value in 'values' was replaced by a string
+       for (idx=0; idx<report['values'].length; idx++) {
+                expect(typeof report['values'][idx] === 'string').toBeTruthy();
+        }
+
+       // Check that each value in 'other' has remained untouched, as it is not a value or range
+       for (idx=0; idx<report['other'].length; idx++) {
+                expect(Array.isArray(report['other'][idx])).toBeTruthy();
+        }
+
+      }
+    });
+
     it('should submit', () => {
       component.onSubmit();
       const req = httpTesting.expectOne('api/telemetry');
index e316f9327d0901d3d449a6790c517cc3ade55df8..17bec010cb75c76b15593590613104a7c1af82cd 100644 (file)
@@ -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),