]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/shared/smart-list/smart-list.component.spec.ts
import ceph quincy 17.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / shared / smart-list / smart-list.component.spec.ts
index 2827d67ec87f819ba30d9ac396ffae04c6cf66e6..54c436ca6f3284c6bfdffebfca3023db9fe1a6d1 100644 (file)
@@ -10,7 +10,12 @@ import { NgxPipeFunctionModule } from 'ngx-pipe-function';
 import { of } from 'rxjs';
 
 import { OsdService } from '~/app/shared/api/osd.service';
-import { HddSmartDataV1, NvmeSmartDataV1, SmartDataResult } from '~/app/shared/models/smart';
+import {
+  AtaSmartDataV1,
+  IscsiSmartDataV1,
+  NvmeSmartDataV1,
+  SmartDataResult
+} from '~/app/shared/models/smart';
 import { SharedModule } from '~/app/shared/shared.module';
 import { configureTestBed } from '~/testing/unit-test-helper';
 import { SmartListComponent } from './smart-list.component';
@@ -20,8 +25,9 @@ describe('OsdSmartListComponent', () => {
   let fixture: ComponentFixture<SmartListComponent>;
   let osdService: OsdService;
 
-  const SMART_DATA_HDD_VERSION_1_0: HddSmartDataV1 = require('./fixtures/smart_data_version_1_0_hdd_response.json');
+  const SMART_DATA_ATA_VERSION_1_0: AtaSmartDataV1 = require('./fixtures/smart_data_version_1_0_ata_response.json');
   const SMART_DATA_NVME_VERSION_1_0: NvmeSmartDataV1 = require('./fixtures/smart_data_version_1_0_nvme_response.json');
+  const SMART_DATA_SCSI_VERSION_1_0: IscsiSmartDataV1 = require('./fixtures/smart_data_version_1_0_scsi_response.json');
 
   /**
    * Sets attributes for _all_ returned devices according to the given path. The syntax is the same
@@ -38,7 +44,7 @@ describe('OsdSmartListComponent', () => {
    */
   const patchData = (path: string, newValue: any): any => {
     return _.reduce(
-      _.cloneDeep(SMART_DATA_HDD_VERSION_1_0),
+      _.cloneDeep(SMART_DATA_ATA_VERSION_1_0),
       (result: object, dataObj, deviceId) => {
         result[deviceId] = _.set<any>(dataObj, path, newValue);
         return result;
@@ -52,18 +58,21 @@ describe('OsdSmartListComponent', () => {
    * of `OsdService`. Determines which data is returned.
    */
   const initializeComponentWithData = (
-    dataType: 'hdd_v1' | 'nvme_v1',
+    dataType: 'hdd_v1' | 'nvme_v1' | 'hdd_v1_scsi',
     patch: { [path: string]: any } = null,
     simpleChanges?: SimpleChanges
   ) => {
-    let data: HddSmartDataV1 | NvmeSmartDataV1;
+    let data: AtaSmartDataV1 | NvmeSmartDataV1 | IscsiSmartDataV1;
     switch (dataType) {
       case 'hdd_v1':
-        data = SMART_DATA_HDD_VERSION_1_0;
+        data = SMART_DATA_ATA_VERSION_1_0;
         break;
       case 'nvme_v1':
         data = SMART_DATA_NVME_VERSION_1_0;
         break;
+      case 'hdd_v1_scsi':
+        data = SMART_DATA_SCSI_VERSION_1_0;
+        break;
     }
 
     if (_.isObject(patch)) {
@@ -131,7 +140,7 @@ describe('OsdSmartListComponent', () => {
     expect(component).toBeTruthy();
   });
 
-  describe('tests HDD version 1.x', () => {
+  describe('tests ATA version 1.x', () => {
     beforeEach(() => initializeComponentWithData('hdd_v1'));
 
     it('should return with proper keys', () => {
@@ -169,6 +178,23 @@ describe('OsdSmartListComponent', () => {
     });
   });
 
+  describe('tests SCSI version 1.x', () => {
+    beforeEach(() => initializeComponentWithData('hdd_v1_scsi'));
+
+    it('should return with proper keys', () => {
+      _.each(component.data, (smartData, _deviceId) => {
+        expect(_.keys(smartData)).toEqual(['info', 'smart', 'device', 'identifier']);
+      });
+    });
+
+    it('should not contain excluded keys in `info`', () => {
+      const excludes = ['scsi_error_counter_log', 'scsi_grown_defect_list'];
+      _.each(component.data, (smartData: SmartDataResult, _deviceId) => {
+        _.each(excludes, (exclude) => expect(smartData.info[exclude]).toBeUndefined());
+      });
+    });
+  });
+
   it('should not work for version 2.x', () => {
     initializeComponentWithData('nvme_v1', { json_format_version: [2, 0] });
     expect(component.data).toEqual({});