]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
238ac788be247a47faa360cb92bc3a597250b912
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { RgwOverviewDashboardComponent } from './rgw-overview-dashboard.component';
4 import { of } from 'rxjs';
5 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
6 import { RgwDaemon } from '../models/rgw-daemon';
7 import { HttpClientTestingModule } from '@angular/common/http/testing';
8 import { CardComponent } from '../../dashboard-v3/card/card.component';
9 import { CardRowComponent } from '../../dashboard-v3/card-row/card-row.component';
10 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
11 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
12 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
13 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
14 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
15 import { RgwUserService } from '~/app/shared/api/rgw-user.service';
16 import { HealthService } from '~/app/shared/api/health.service';
17
18 describe('RgwOverviewDashboardComponent', () => {
19   let component: RgwOverviewDashboardComponent;
20   let fixture: ComponentFixture<RgwOverviewDashboardComponent>;
21   const daemon: RgwDaemon = {
22     id: '8000',
23     service_map_id: '4803',
24     version: 'ceph version',
25     server_hostname: 'ceph',
26     realm_name: 'realm1',
27     zonegroup_name: 'zg1-realm1',
28     zone_name: 'zone1-zg1-realm1',
29     default: true,
30     port: 80
31   };
32
33   const realmList = {
34     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
35     realms: ['realm2', 'realm1']
36   };
37
38   const zonegroupList = {
39     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
40     zonegroups: ['zg-1', 'zg-2', 'zg-3']
41   };
42
43   const zoneList = {
44     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
45     zones: ['zone4', 'zone5', 'zone6', 'zone7']
46   };
47
48   const bucketList = [
49     {
50       bucket: 'bucket',
51       owner: 'testid',
52       usage: {
53         'rgw.main': {
54           size_actual: 4,
55           num_objects: 2
56         },
57         'rgw.none': {
58           size_actual: 6,
59           num_objects: 6
60         }
61       },
62       bucket_quota: {
63         max_size: 20,
64         max_objects: 10,
65         enabled: true
66       }
67     },
68     {
69       bucket: 'bucket2',
70       owner: 'testid',
71       usage: {
72         'rgw.main': {
73           size_actual: 4,
74           num_objects: 2
75         },
76         'rgw.none': {
77           size_actual: 6,
78           num_objects: 6
79         }
80       },
81       bucket_quota: {
82         max_size: 20,
83         max_objects: 10,
84         enabled: true
85       }
86     }
87   ];
88
89   const userList = [
90     {
91       user_id: 'testid',
92       stats: {
93         size_actual: 6,
94         num_objects: 6
95       },
96       user_quota: {
97         max_size: 20,
98         max_objects: 10,
99         enabled: true
100       }
101     },
102     {
103       user_id: 'testid2',
104       stats: {
105         size_actual: 6,
106         num_objects: 6
107       },
108       user_quota: {
109         max_size: 20,
110         max_objects: 10,
111         enabled: true
112       }
113     }
114   ];
115
116   const healthData = {
117     total_objects: '290',
118     total_pool_bytes_used: 9338880
119   };
120
121   let listDaemonsSpy: jest.SpyInstance;
122   let listZonesSpy: jest.SpyInstance;
123   let listZonegroupsSpy: jest.SpyInstance;
124   let listRealmsSpy: jest.SpyInstance;
125   let listBucketsSpy: jest.SpyInstance;
126   let listUsersSpy: jest.SpyInstance;
127   let healthDataSpy: jest.SpyInstance;
128
129   beforeEach(async () => {
130     await TestBed.configureTestingModule({
131       declarations: [
132         RgwOverviewDashboardComponent,
133         CardComponent,
134         CardRowComponent,
135         DimlessBinaryPipe
136       ],
137       imports: [HttpClientTestingModule]
138     }).compileComponents();
139   });
140
141   beforeEach(() => {
142     listDaemonsSpy = jest
143       .spyOn(TestBed.inject(RgwDaemonService), 'list')
144       .mockReturnValue(of([daemon]));
145     listRealmsSpy = jest
146       .spyOn(TestBed.inject(RgwRealmService), 'list')
147       .mockReturnValue(of(realmList));
148     listZonegroupsSpy = jest
149       .spyOn(TestBed.inject(RgwZonegroupService), 'list')
150       .mockReturnValue(of(zonegroupList));
151     listZonesSpy = jest.spyOn(TestBed.inject(RgwZoneService), 'list').mockReturnValue(of(zoneList));
152     listBucketsSpy = jest
153       .spyOn(TestBed.inject(RgwBucketService), 'list')
154       .mockReturnValue(of(bucketList));
155     listUsersSpy = jest.spyOn(TestBed.inject(RgwUserService), 'list').mockReturnValue(of(userList));
156     healthDataSpy = jest
157       .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
158       .mockReturnValue(of(healthData));
159     fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
160     component = fixture.componentInstance;
161     fixture.detectChanges();
162   });
163
164   it('should create', () => {
165     expect(component).toBeTruthy();
166   });
167
168   it('should render all cards', () => {
169     fixture.detectChanges();
170     const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
171     expect(dashboardCards.length).toBe(6);
172   });
173
174   it('should get corresponding data into Daemons', () => {
175     expect(listDaemonsSpy).toHaveBeenCalled();
176     expect(component.rgwDaemonCount).toEqual(1);
177   });
178
179   it('should get corresponding data into Realms', () => {
180     expect(listRealmsSpy).toHaveBeenCalled();
181     expect(component.rgwRealmCount).toEqual(2);
182   });
183
184   it('should get corresponding data into Zonegroups', () => {
185     expect(listZonegroupsSpy).toHaveBeenCalled();
186     expect(component.rgwZonegroupCount).toEqual(3);
187   });
188
189   it('should get corresponding data into Zones', () => {
190     expect(listZonesSpy).toHaveBeenCalled();
191     expect(component.rgwZoneCount).toEqual(4);
192   });
193
194   it('should get corresponding data into Buckets', () => {
195     expect(listBucketsSpy).toHaveBeenCalled();
196     expect(component.rgwBucketCount).toEqual(2);
197   });
198
199   it('should get corresponding data into Users', () => {
200     expect(listUsersSpy).toHaveBeenCalled();
201     expect(component.UserCount).toEqual(2);
202   });
203
204   it('should get corresponding data into Objects and capacity', () => {
205     expect(healthDataSpy).toHaveBeenCalled();
206     expect(component.objectCount).toEqual('290');
207     expect(component.totalPoolUsedBytes).toEqual(9338880);
208   });
209 });