]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / testing / unit-test-helper.ts
index 539ee792f4a38661c5273f8ea8e4986719ba3cda..6f625003380f59d5317e5ccf1cba1df1e5756a23 100644 (file)
@@ -10,9 +10,10 @@ import { TableActionsComponent } from '../app/shared/datatable/table-actions/tab
 import { CdFormGroup } from '../app/shared/forms/cd-form-group';
 import { Permission } from '../app/shared/models/permissions';
 import {
-  PrometheusAlert,
-  PrometheusNotification,
-  PrometheusNotificationAlert
+  AlertmanagerAlert,
+  AlertmanagerNotification,
+  AlertmanagerNotificationAlert,
+  PrometheusRule
 } from '../app/shared/models/prometheus-alerts';
 import { _DEV_ } from '../unit-test-configuration';
 
@@ -61,6 +62,11 @@ export class PermissionHelper {
     return this.tableActions;
   }
 
+  // Overwrite if needed
+  createSelection(): object {
+    return {};
+  }
+
   testScenarios({
     fn,
     empty,
@@ -76,17 +82,19 @@ export class PermissionHelper {
   }) {
     this.testScenario(
       // 'multiple selections'
-      [{}, {}],
+      [this.createSelection(), this.createSelection()],
       fn,
       _.isUndefined(multiple) ? empty : multiple
     );
+    const executing = this.createSelection();
+    executing['cdExecuting'] = 'someAction';
     this.testScenario(
       // 'select executing item'
-      [{ cdExecuting: 'someAction' }],
+      [executing],
       fn,
       _.isUndefined(singleExecuting) ? single : singleExecuting
     );
-    this.testScenario([{}], fn, single); // 'select non-executing item'
+    this.testScenario([this.createSelection()], fn, single); // 'select non-executing item'
     this.testScenario([], fn, empty); // 'no selection'
   }
 
@@ -216,22 +224,52 @@ export class FixtureHelper {
 }
 
 export class PrometheusHelper {
-  createAlert(name, state = 'active', timeMultiplier = 1) {
+  createSilence(id) {
+    return {
+      id: id,
+      createdBy: `Creator of ${id}`,
+      comment: `A comment for ${id}`,
+      startsAt: new Date('2022-02-22T22:22:00').toISOString(),
+      endsAt: new Date('2022-02-23T22:22:00').toISOString(),
+      matchers: [
+        {
+          name: 'job',
+          value: 'someJob',
+          isRegex: true
+        }
+      ]
+    };
+  }
+
+  createRule(name, severity, alerts: any[]): PrometheusRule {
+    return {
+      name: name,
+      labels: {
+        severity: severity
+      },
+      alerts: alerts
+    } as PrometheusRule;
+  }
+
+  createAlert(name, state = 'active', timeMultiplier = 1): AlertmanagerAlert {
     return {
       fingerprint: name,
       status: { state },
       labels: {
-        alertname: name
+        alertname: name,
+        instance: 'someInstance',
+        job: 'someJob',
+        severity: 'someSeverity'
       },
       annotations: {
         summary: `${name} is ${state}`
       },
       generatorURL: `http://${name}`,
       startsAt: new Date(new Date('2022-02-22').getTime() * timeMultiplier).toString()
-    } as PrometheusAlert;
+    } as AlertmanagerAlert;
   }
 
-  createNotificationAlert(name, status = 'firing') {
+  createNotificationAlert(name, status = 'firing'): AlertmanagerNotificationAlert {
     return {
       status: status,
       labels: {
@@ -241,15 +279,15 @@ export class PrometheusHelper {
         summary: `${name} is ${status}`
       },
       generatorURL: `http://${name}`
-    } as PrometheusNotificationAlert;
+    } as AlertmanagerNotificationAlert;
   }
 
-  createNotification(alertNumber = 1, status = 'firing') {
+  createNotification(alertNumber = 1, status = 'firing'): AlertmanagerNotification {
     const alerts = [];
     for (let i = 0; i < alertNumber; i++) {
       alerts.push(this.createNotificationAlert('alert' + i, status));
     }
-    return { alerts, status } as PrometheusNotification;
+    return { alerts, status } as AlertmanagerNotification;
   }
 
   createLink(url) {