1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { OsdService } from './osd.service';
7 describe('OsdService', () => {
8 let service: OsdService;
9 let httpTesting: HttpTestingController;
12 providers: [OsdService],
13 imports: [HttpClientTestingModule]
17 service = TestBed.inject(OsdService);
18 httpTesting = TestBed.inject(HttpTestingController);
25 it('should be created', () => {
26 expect(service).toBeTruthy();
29 it('should call create', () => {
31 method: 'drive_groups',
35 service_id: 'all_hdd',
43 service_id: 'host1_ssd',
44 host_pattern: 'host1',
50 tracking_id: 'all_hdd, host1_ssd'
52 service.create(post_data.data).subscribe();
53 const req = httpTesting.expectOne('api/osd');
54 expect(req.request.method).toBe('POST');
55 expect(req.request.body).toEqual(post_data);
58 it('should call delete', () => {
60 service.delete(id, true, true).subscribe();
61 const req = httpTesting.expectOne(`api/osd/${id}?preserve_id=true&force=true`);
62 expect(req.request.method).toBe('DELETE');
65 it('should call getList', () => {
66 service.getList().subscribe();
67 const req = httpTesting.expectOne('api/osd');
68 expect(req.request.method).toBe('GET');
71 it('should call getDetails', () => {
72 service.getDetails(1).subscribe();
73 const req = httpTesting.expectOne('api/osd/1');
74 expect(req.request.method).toBe('GET');
77 it('should call scrub, with deep=true', () => {
78 service.scrub('foo', true).subscribe();
79 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=true');
80 expect(req.request.method).toBe('POST');
83 it('should call scrub, with deep=false', () => {
84 service.scrub('foo', false).subscribe();
85 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=false');
86 expect(req.request.method).toBe('POST');
89 it('should call getFlags', () => {
90 service.getFlags().subscribe();
91 const req = httpTesting.expectOne('api/osd/flags');
92 expect(req.request.method).toBe('GET');
95 it('should call updateFlags', () => {
96 service.updateFlags(['foo']).subscribe();
97 const req = httpTesting.expectOne('api/osd/flags');
98 expect(req.request.method).toBe('PUT');
99 expect(req.request.body).toEqual({ flags: ['foo'] });
102 it('should call updateIndividualFlags to update individual flags', () => {
103 const flags = { noin: true, noout: true };
105 service.updateIndividualFlags(flags, ids).subscribe();
106 const req = httpTesting.expectOne('api/osd/flags/individual');
107 expect(req.request.method).toBe('PUT');
108 expect(req.request.body).toEqual({ flags: flags, ids: ids });
111 it('should mark the OSD out', () => {
112 service.markOut(1).subscribe();
113 const req = httpTesting.expectOne('api/osd/1/mark');
114 expect(req.request.method).toBe('PUT');
115 expect(req.request.body).toEqual({ action: 'out' });
118 it('should mark the OSD in', () => {
119 service.markIn(1).subscribe();
120 const req = httpTesting.expectOne('api/osd/1/mark');
121 expect(req.request.method).toBe('PUT');
122 expect(req.request.body).toEqual({ action: 'in' });
125 it('should mark the OSD down', () => {
126 service.markDown(1).subscribe();
127 const req = httpTesting.expectOne('api/osd/1/mark');
128 expect(req.request.method).toBe('PUT');
129 expect(req.request.body).toEqual({ action: 'down' });
132 it('should reweight an OSD', () => {
133 service.reweight(1, 0.5).subscribe();
134 const req = httpTesting.expectOne('api/osd/1/reweight');
135 expect(req.request.method).toBe('POST');
136 expect(req.request.body).toEqual({ weight: 0.5 });
139 it('should update OSD', () => {
140 service.update(1, 'hdd').subscribe();
141 const req = httpTesting.expectOne('api/osd/1');
142 expect(req.request.method).toBe('PUT');
143 expect(req.request.body).toEqual({ device_class: 'hdd' });
146 it('should mark an OSD lost', () => {
147 service.markLost(1).subscribe();
148 const req = httpTesting.expectOne('api/osd/1/mark');
149 expect(req.request.method).toBe('PUT');
150 expect(req.request.body).toEqual({ action: 'lost' });
153 it('should purge an OSD', () => {
154 service.purge(1).subscribe();
155 const req = httpTesting.expectOne('api/osd/1/purge');
156 expect(req.request.method).toBe('POST');
159 it('should destroy an OSD', () => {
160 service.destroy(1).subscribe();
161 const req = httpTesting.expectOne('api/osd/1/destroy');
162 expect(req.request.method).toBe('POST');
165 it('should return if it is safe to destroy an OSD', () => {
166 service.safeToDestroy('[0,1]').subscribe();
167 const req = httpTesting.expectOne('api/osd/safe_to_destroy?ids=[0,1]');
168 expect(req.request.method).toBe('GET');
171 it('should call the devices endpoint to retrieve smart data', () => {
172 service.getDevices(1).subscribe();
173 const req = httpTesting.expectOne('api/osd/1/devices');
174 expect(req.request.method).toBe('GET');