1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed, i18nProviders } 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, i18nProviders],
13 imports: [HttpClientTestingModule]
17 service = TestBed.get(OsdService);
18 httpTesting = TestBed.get(HttpTestingController);
25 it('should be created', () => {
26 expect(service).toBeTruthy();
29 it('should call getList', () => {
30 service.getList().subscribe();
31 const req = httpTesting.expectOne('api/osd');
32 expect(req.request.method).toBe('GET');
35 it('should call getDetails', () => {
36 service.getDetails(1).subscribe();
37 const req = httpTesting.expectOne('api/osd/1');
38 expect(req.request.method).toBe('GET');
41 it('should call scrub, with deep=true', () => {
42 service.scrub('foo', true).subscribe();
43 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=true');
44 expect(req.request.method).toBe('POST');
47 it('should call scrub, with deep=false', () => {
48 service.scrub('foo', false).subscribe();
49 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=false');
50 expect(req.request.method).toBe('POST');
53 it('should call getFlags', () => {
54 service.getFlags().subscribe();
55 const req = httpTesting.expectOne('api/osd/flags');
56 expect(req.request.method).toBe('GET');
59 it('should call updateFlags', () => {
60 service.updateFlags(['foo']).subscribe();
61 const req = httpTesting.expectOne('api/osd/flags');
62 expect(req.request.method).toBe('PUT');
63 expect(req.request.body).toEqual({ flags: ['foo'] });
66 it('should mark the OSD out', () => {
67 service.markOut(1).subscribe();
68 const req = httpTesting.expectOne('api/osd/1/mark_out');
69 expect(req.request.method).toBe('POST');
72 it('should mark the OSD in', () => {
73 service.markIn(1).subscribe();
74 const req = httpTesting.expectOne('api/osd/1/mark_in');
75 expect(req.request.method).toBe('POST');
78 it('should mark the OSD down', () => {
79 service.markDown(1).subscribe();
80 const req = httpTesting.expectOne('api/osd/1/mark_down');
81 expect(req.request.method).toBe('POST');
84 it('should reweight an OSD', () => {
85 service.reweight(1, 0.5).subscribe();
86 const req = httpTesting.expectOne('api/osd/1/reweight');
87 expect(req.request.method).toBe('POST');
88 expect(req.request.body).toEqual({ weight: 0.5 });
91 it('should mark an OSD lost', () => {
92 service.markLost(1).subscribe();
93 const req = httpTesting.expectOne('api/osd/1/mark_lost');
94 expect(req.request.method).toBe('POST');
97 it('should purge an OSD', () => {
98 service.purge(1).subscribe();
99 const req = httpTesting.expectOne('api/osd/1/purge');
100 expect(req.request.method).toBe('POST');
103 it('should destroy an OSD', () => {
104 service.destroy(1).subscribe();
105 const req = httpTesting.expectOne('api/osd/1/destroy');
106 expect(req.request.method).toBe('POST');
109 it('should return if it is safe to destroy an OSD', () => {
110 service.safeToDestroy(1).subscribe();
111 const req = httpTesting.expectOne('api/osd/1/safe_to_destroy');
112 expect(req.request.method).toBe('GET');