]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
2 | import { TestBed } from '@angular/core/testing'; | |
3 | ||
f67539c2 | 4 | import { configureTestBed } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
5 | import { OsdService } from './osd.service'; |
6 | ||
7 | describe('OsdService', () => { | |
8 | let service: OsdService; | |
9 | let httpTesting: HttpTestingController; | |
10 | ||
11 | configureTestBed({ | |
f67539c2 | 12 | providers: [OsdService], |
11fdf7f2 TL |
13 | imports: [HttpClientTestingModule] |
14 | }); | |
15 | ||
16 | beforeEach(() => { | |
f67539c2 TL |
17 | service = TestBed.inject(OsdService); |
18 | httpTesting = TestBed.inject(HttpTestingController); | |
11fdf7f2 TL |
19 | }); |
20 | ||
21 | afterEach(() => { | |
22 | httpTesting.verify(); | |
23 | }); | |
24 | ||
25 | it('should be created', () => { | |
26 | expect(service).toBeTruthy(); | |
27 | }); | |
28 | ||
9f95a23c | 29 | it('should call create', () => { |
2a845540 | 30 | const trackingId = 'all_hdd, host1_ssd'; |
9f95a23c TL |
31 | const post_data = { |
32 | method: 'drive_groups', | |
33 | data: [ | |
34 | { | |
35 | service_name: 'osd', | |
36 | service_id: 'all_hdd', | |
37 | host_pattern: '*', | |
38 | data_devices: { | |
39 | rotational: true | |
40 | } | |
41 | }, | |
42 | { | |
43 | service_name: 'osd', | |
44 | service_id: 'host1_ssd', | |
45 | host_pattern: 'host1', | |
46 | data_devices: { | |
47 | rotational: false | |
48 | } | |
49 | } | |
50 | ], | |
2a845540 | 51 | tracking_id: trackingId |
9f95a23c | 52 | }; |
2a845540 | 53 | service.create(post_data.data, trackingId).subscribe(); |
9f95a23c TL |
54 | const req = httpTesting.expectOne('api/osd'); |
55 | expect(req.request.method).toBe('POST'); | |
56 | expect(req.request.body).toEqual(post_data); | |
57 | }); | |
58 | ||
f6b5b4d7 TL |
59 | it('should call delete', () => { |
60 | const id = 1; | |
61 | service.delete(id, true, true).subscribe(); | |
62 | const req = httpTesting.expectOne(`api/osd/${id}?preserve_id=true&force=true`); | |
63 | expect(req.request.method).toBe('DELETE'); | |
64 | }); | |
65 | ||
11fdf7f2 TL |
66 | it('should call getList', () => { |
67 | service.getList().subscribe(); | |
68 | const req = httpTesting.expectOne('api/osd'); | |
69 | expect(req.request.method).toBe('GET'); | |
70 | }); | |
71 | ||
72 | it('should call getDetails', () => { | |
73 | service.getDetails(1).subscribe(); | |
74 | const req = httpTesting.expectOne('api/osd/1'); | |
75 | expect(req.request.method).toBe('GET'); | |
76 | }); | |
77 | ||
78 | it('should call scrub, with deep=true', () => { | |
79 | service.scrub('foo', true).subscribe(); | |
80 | const req = httpTesting.expectOne('api/osd/foo/scrub?deep=true'); | |
81 | expect(req.request.method).toBe('POST'); | |
82 | }); | |
83 | ||
84 | it('should call scrub, with deep=false', () => { | |
85 | service.scrub('foo', false).subscribe(); | |
86 | const req = httpTesting.expectOne('api/osd/foo/scrub?deep=false'); | |
87 | expect(req.request.method).toBe('POST'); | |
88 | }); | |
89 | ||
90 | it('should call getFlags', () => { | |
91 | service.getFlags().subscribe(); | |
92 | const req = httpTesting.expectOne('api/osd/flags'); | |
93 | expect(req.request.method).toBe('GET'); | |
94 | }); | |
95 | ||
96 | it('should call updateFlags', () => { | |
97 | service.updateFlags(['foo']).subscribe(); | |
98 | const req = httpTesting.expectOne('api/osd/flags'); | |
99 | expect(req.request.method).toBe('PUT'); | |
100 | expect(req.request.body).toEqual({ flags: ['foo'] }); | |
101 | }); | |
102 | ||
adb31ebb TL |
103 | it('should call updateIndividualFlags to update individual flags', () => { |
104 | const flags = { noin: true, noout: true }; | |
105 | const ids = [0, 1]; | |
106 | service.updateIndividualFlags(flags, ids).subscribe(); | |
107 | const req = httpTesting.expectOne('api/osd/flags/individual'); | |
108 | expect(req.request.method).toBe('PUT'); | |
109 | expect(req.request.body).toEqual({ flags: flags, ids: ids }); | |
110 | }); | |
111 | ||
11fdf7f2 TL |
112 | it('should mark the OSD out', () => { |
113 | service.markOut(1).subscribe(); | |
f67539c2 TL |
114 | const req = httpTesting.expectOne('api/osd/1/mark'); |
115 | expect(req.request.method).toBe('PUT'); | |
116 | expect(req.request.body).toEqual({ action: 'out' }); | |
11fdf7f2 TL |
117 | }); |
118 | ||
119 | it('should mark the OSD in', () => { | |
120 | service.markIn(1).subscribe(); | |
f67539c2 TL |
121 | const req = httpTesting.expectOne('api/osd/1/mark'); |
122 | expect(req.request.method).toBe('PUT'); | |
123 | expect(req.request.body).toEqual({ action: 'in' }); | |
11fdf7f2 TL |
124 | }); |
125 | ||
126 | it('should mark the OSD down', () => { | |
127 | service.markDown(1).subscribe(); | |
f67539c2 TL |
128 | const req = httpTesting.expectOne('api/osd/1/mark'); |
129 | expect(req.request.method).toBe('PUT'); | |
130 | expect(req.request.body).toEqual({ action: 'down' }); | |
11fdf7f2 TL |
131 | }); |
132 | ||
133 | it('should reweight an OSD', () => { | |
134 | service.reweight(1, 0.5).subscribe(); | |
135 | const req = httpTesting.expectOne('api/osd/1/reweight'); | |
136 | expect(req.request.method).toBe('POST'); | |
137 | expect(req.request.body).toEqual({ weight: 0.5 }); | |
138 | }); | |
139 | ||
9f95a23c TL |
140 | it('should update OSD', () => { |
141 | service.update(1, 'hdd').subscribe(); | |
142 | const req = httpTesting.expectOne('api/osd/1'); | |
143 | expect(req.request.method).toBe('PUT'); | |
144 | expect(req.request.body).toEqual({ device_class: 'hdd' }); | |
145 | }); | |
146 | ||
11fdf7f2 TL |
147 | it('should mark an OSD lost', () => { |
148 | service.markLost(1).subscribe(); | |
f67539c2 TL |
149 | const req = httpTesting.expectOne('api/osd/1/mark'); |
150 | expect(req.request.method).toBe('PUT'); | |
151 | expect(req.request.body).toEqual({ action: 'lost' }); | |
11fdf7f2 TL |
152 | }); |
153 | ||
154 | it('should purge an OSD', () => { | |
155 | service.purge(1).subscribe(); | |
156 | const req = httpTesting.expectOne('api/osd/1/purge'); | |
157 | expect(req.request.method).toBe('POST'); | |
158 | }); | |
159 | ||
160 | it('should destroy an OSD', () => { | |
161 | service.destroy(1).subscribe(); | |
162 | const req = httpTesting.expectOne('api/osd/1/destroy'); | |
163 | expect(req.request.method).toBe('POST'); | |
164 | }); | |
165 | ||
166 | it('should return if it is safe to destroy an OSD', () => { | |
9f95a23c TL |
167 | service.safeToDestroy('[0,1]').subscribe(); |
168 | const req = httpTesting.expectOne('api/osd/safe_to_destroy?ids=[0,1]'); | |
169 | expect(req.request.method).toBe('GET'); | |
170 | }); | |
171 | ||
172 | it('should call the devices endpoint to retrieve smart data', () => { | |
173 | service.getDevices(1).subscribe(); | |
174 | const req = httpTesting.expectOne('api/osd/1/devices'); | |
11fdf7f2 TL |
175 | expect(req.request.method).toBe('GET'); |
176 | }); | |
2a845540 TL |
177 | |
178 | it('should call getDeploymentOptions', () => { | |
179 | service.getDeploymentOptions().subscribe(); | |
180 | const req = httpTesting.expectOne('ui-api/osd/deployment_options'); | |
181 | expect(req.request.method).toBe('GET'); | |
182 | }); | |
11fdf7f2 | 183 | }); |