]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
6071d2d7eb7334668ac8b952b0e537518a896c3b
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3
4 import { TreeModel, TreeModule } from '@circlon/angular-tree-component';
5
6 import { configureTestBed } from '~/testing/unit-test-helper';
7 import { SharedModule } from '~/app/shared/shared.module';
8 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
9
10 describe('IscsiTargetDetailsComponent', () => {
11   let component: IscsiTargetDetailsComponent;
12   let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
13
14   configureTestBed({
15     declarations: [IscsiTargetDetailsComponent],
16     imports: [BrowserAnimationsModule, TreeModule, SharedModule]
17   });
18
19   beforeEach(() => {
20     fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
21     component = fixture.componentInstance;
22
23     component.settings = {
24       config: { minimum_gateways: 2 },
25       disk_default_controls: {
26         'backstore:1': {
27           hw_max_sectors: 1024,
28           max_data_area_mb: 8
29         },
30         'backstore:2': {
31           hw_max_sectors: 1024,
32           max_data_area_mb: 8
33         }
34       },
35       target_default_controls: {
36         cmdsn_depth: 128,
37         dataout_timeout: 20
38       },
39       backstores: ['backstore:1', 'backstore:2'],
40       default_backstore: 'backstore:1'
41     };
42     component.selection = undefined;
43     component.selection = {
44       target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
45       portals: [{ host: 'node1', ip: '192.168.100.201' }],
46       disks: [
47         {
48           pool: 'rbd',
49           image: 'disk_1',
50           backstore: 'backstore:1',
51           controls: { hw_max_sectors: 1 }
52         }
53       ],
54       clients: [
55         {
56           client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
57           luns: [{ pool: 'rbd', image: 'disk_1' }],
58           auth: {
59             user: 'myiscsiusername'
60           },
61           info: {
62             alias: 'myhost',
63             ip_address: ['192.168.200.1'],
64             state: { LOGGED_IN: ['node1'] }
65           }
66         }
67       ],
68       groups: [],
69       target_controls: { dataout_timeout: 2 }
70     };
71
72     fixture.detectChanges();
73   });
74
75   it('should create', () => {
76     expect(component).toBeTruthy();
77   });
78
79   it('should empty data and generateTree when ngOnChanges is called', () => {
80     const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
81     component.data = tempData;
82     fixture.detectChanges();
83
84     expect(component.data).toEqual(tempData);
85     expect(component.metadata).toEqual({});
86     expect(component.nodes).toEqual([]);
87
88     component.ngOnChanges();
89
90     expect(component.data).toBeUndefined();
91     expect(component.metadata).toEqual({
92       'client_iqn.1994-05.com.redhat:rh7-client': {
93         user: 'myiscsiusername',
94         alias: 'myhost',
95         ip_address: ['192.168.200.1'],
96         logged_in: ['node1']
97       },
98       disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
99       root: { dataout_timeout: 2 }
100     });
101     expect(component.nodes).toEqual([
102       {
103         cdIcon: 'fa fa-lg fa fa-bullseye',
104         cdId: 'root',
105         children: [
106           {
107             cdIcon: 'fa fa-lg fa fa-hdd-o',
108             children: [
109               {
110                 cdIcon: 'fa fa-hdd-o',
111                 cdId: 'disk_rbd_disk_1',
112                 name: 'rbd/disk_1'
113               }
114             ],
115             isExpanded: true,
116             name: 'Disks'
117           },
118           {
119             cdIcon: 'fa fa-lg fa fa-server',
120             children: [
121               {
122                 cdIcon: 'fa fa-server',
123                 name: 'node1:192.168.100.201'
124               }
125             ],
126             isExpanded: true,
127             name: 'Portals'
128           },
129           {
130             cdIcon: 'fa fa-lg fa fa-user',
131             children: [
132               {
133                 cdIcon: 'fa fa-user',
134                 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
135                 children: [
136                   {
137                     cdIcon: 'fa fa-hdd-o',
138                     cdId: 'disk_rbd_disk_1',
139                     name: 'rbd/disk_1'
140                   }
141                 ],
142                 name: 'iqn.1994-05.com.redhat:rh7-client',
143                 status: 'logged_in'
144               }
145             ],
146             isExpanded: true,
147             name: 'Initiators'
148           },
149           {
150             cdIcon: 'fa fa-lg fa fa-users',
151             children: [],
152             isExpanded: true,
153             name: 'Groups'
154           }
155         ],
156         isExpanded: true,
157         name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
158       }
159     ]);
160   });
161
162   describe('should update data when onNodeSelected is called', () => {
163     let tree: TreeModel;
164
165     beforeEach(() => {
166       component.ngOnChanges();
167       tree = component.tree.treeModel;
168       fixture.detectChanges();
169     });
170
171     it('with target selected', () => {
172       const node = tree.getNodeBy({ data: { cdId: 'root' } });
173       component.onNodeSelected(tree, node);
174       expect(component.data).toEqual([
175         { current: 128, default: 128, displayName: 'cmdsn_depth' },
176         { current: 2, default: 20, displayName: 'dataout_timeout' }
177       ]);
178     });
179
180     it('with disk selected', () => {
181       const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
182       component.onNodeSelected(tree, node);
183       expect(component.data).toEqual([
184         { current: 1, default: 1024, displayName: 'hw_max_sectors' },
185         { current: 8, default: 8, displayName: 'max_data_area_mb' },
186         { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
187       ]);
188     });
189
190     it('with initiator selected', () => {
191       const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
192       component.onNodeSelected(tree, node);
193       expect(component.data).toEqual([
194         { current: 'myiscsiusername', default: undefined, displayName: 'user' },
195         { current: 'myhost', default: undefined, displayName: 'alias' },
196         { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
197         { current: ['node1'], default: undefined, displayName: 'logged_in' }
198       ]);
199     });
200
201     it('with any other selected', () => {
202       const node = tree.getNodeBy({ data: { name: 'Disks' } });
203       component.onNodeSelected(tree, node);
204       expect(component.data).toBeUndefined();
205     });
206   });
207 });