]>
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 { CephfsService } from './cephfs.service'; |
6 | ||
7 | describe('CephfsService', () => { | |
8 | let service: CephfsService; | |
9 | let httpTesting: HttpTestingController; | |
10 | ||
11 | configureTestBed({ | |
12 | imports: [HttpClientTestingModule], | |
13 | providers: [CephfsService] | |
14 | }); | |
15 | ||
16 | beforeEach(() => { | |
f67539c2 TL |
17 | service = TestBed.inject(CephfsService); |
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 | ||
29 | it('should call list', () => { | |
30 | service.list().subscribe(); | |
31 | const req = httpTesting.expectOne('api/cephfs'); | |
32 | expect(req.request.method).toBe('GET'); | |
33 | }); | |
34 | ||
35 | it('should call getCephfs', () => { | |
36 | service.getCephfs(1).subscribe(); | |
37 | const req = httpTesting.expectOne('api/cephfs/1'); | |
38 | expect(req.request.method).toBe('GET'); | |
39 | }); | |
40 | ||
41 | it('should call getClients', () => { | |
42 | service.getClients(1).subscribe(); | |
43 | const req = httpTesting.expectOne('api/cephfs/1/clients'); | |
44 | expect(req.request.method).toBe('GET'); | |
45 | }); | |
46 | ||
9f95a23c TL |
47 | it('should call getTabs', () => { |
48 | service.getTabs(2).subscribe(); | |
49 | const req = httpTesting.expectOne('ui-api/cephfs/2/tabs'); | |
50 | expect(req.request.method).toBe('GET'); | |
51 | }); | |
52 | ||
11fdf7f2 | 53 | it('should call getMdsCounters', () => { |
9f95a23c | 54 | service.getMdsCounters('1').subscribe(); |
11fdf7f2 TL |
55 | const req = httpTesting.expectOne('api/cephfs/1/mds_counters'); |
56 | expect(req.request.method).toBe('GET'); | |
57 | }); | |
9f95a23c TL |
58 | |
59 | it('should call lsDir', () => { | |
60 | service.lsDir(1).subscribe(); | |
61 | const req = httpTesting.expectOne('ui-api/cephfs/1/ls_dir?depth=2'); | |
62 | expect(req.request.method).toBe('GET'); | |
63 | service.lsDir(2, '/some/path').subscribe(); | |
64 | httpTesting.expectOne('ui-api/cephfs/2/ls_dir?depth=2&path=%252Fsome%252Fpath'); | |
65 | }); | |
66 | ||
67 | it('should call mkSnapshot', () => { | |
68 | service.mkSnapshot(3, '/some/path').subscribe(); | |
f67539c2 | 69 | const req = httpTesting.expectOne('api/cephfs/3/snapshot?path=%252Fsome%252Fpath'); |
9f95a23c TL |
70 | expect(req.request.method).toBe('POST'); |
71 | ||
72 | service.mkSnapshot(4, '/some/other/path', 'snap').subscribe(); | |
f67539c2 | 73 | httpTesting.expectOne('api/cephfs/4/snapshot?path=%252Fsome%252Fother%252Fpath&name=snap'); |
9f95a23c TL |
74 | }); |
75 | ||
76 | it('should call rmSnapshot', () => { | |
77 | service.rmSnapshot(1, '/some/path', 'snap').subscribe(); | |
f67539c2 TL |
78 | const req = httpTesting.expectOne('api/cephfs/1/snapshot?path=%252Fsome%252Fpath&name=snap'); |
79 | expect(req.request.method).toBe('DELETE'); | |
9f95a23c TL |
80 | }); |
81 | ||
82 | it('should call updateQuota', () => { | |
f67539c2 TL |
83 | service.quota(1, '/some/path', { max_bytes: 1024 }).subscribe(); |
84 | let req = httpTesting.expectOne('api/cephfs/1/quota?path=%252Fsome%252Fpath'); | |
85 | expect(req.request.method).toBe('PUT'); | |
9f95a23c TL |
86 | expect(req.request.body).toEqual({ max_bytes: 1024 }); |
87 | ||
f67539c2 TL |
88 | service.quota(1, '/some/path', { max_files: 10 }).subscribe(); |
89 | req = httpTesting.expectOne('api/cephfs/1/quota?path=%252Fsome%252Fpath'); | |
90 | expect(req.request.method).toBe('PUT'); | |
9f95a23c TL |
91 | expect(req.request.body).toEqual({ max_files: 10 }); |
92 | ||
f67539c2 TL |
93 | service.quota(1, '/some/path', { max_bytes: 1024, max_files: 10 }).subscribe(); |
94 | req = httpTesting.expectOne('api/cephfs/1/quota?path=%252Fsome%252Fpath'); | |
95 | expect(req.request.method).toBe('PUT'); | |
9f95a23c TL |
96 | expect(req.request.body).toEqual({ max_bytes: 1024, max_files: 10 }); |
97 | }); | |
aee94f69 TL |
98 | |
99 | it('should rename the cephfs volume', () => { | |
100 | const volName = 'testvol'; | |
101 | const newVolName = 'newtestvol'; | |
102 | service.rename(volName, newVolName).subscribe(); | |
103 | const req = httpTesting.expectOne('api/cephfs/rename'); | |
104 | expect(req.request.method).toBe('PUT'); | |
105 | expect(req.request.body).toEqual({ name: 'testvol', new_name: 'newtestvol' }); | |
106 | }); | |
107 | ||
108 | it('should remove the cephfs volume', () => { | |
109 | const volName = 'testvol'; | |
110 | service.remove(volName).subscribe(); | |
111 | const req = httpTesting.expectOne(`api/cephfs/remove/${volName}`); | |
112 | expect(req.request.method).toBe('DELETE'); | |
113 | }); | |
11fdf7f2 | 114 | }); |