]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rgw-bucket.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
3
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { RgwBucketService } from './rgw-bucket.service';
6
7 describe('RgwBucketService', () => {
8 let service: RgwBucketService;
9 let httpTesting: HttpTestingController;
10
11 configureTestBed({
12 providers: [RgwBucketService],
13 imports: [HttpClientTestingModule]
14 });
15
16 beforeEach(() => {
17 service = TestBed.get(RgwBucketService);
18 httpTesting = TestBed.get(HttpTestingController);
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, with enumerate returning empty', () => {
30 let result;
31 service.list().subscribe((resp) => {
32 result = resp;
33 });
34 const req = httpTesting.expectOne('api/rgw/bucket');
35 req.flush([]);
36 expect(req.request.method).toBe('GET');
37 expect(result).toEqual([]);
38 });
39
40 it('should call list, with enumerate returning 2 elements', () => {
41 let result;
42 service.list().subscribe((resp) => {
43 result = resp;
44 });
45 let req = httpTesting.expectOne('api/rgw/bucket');
46 req.flush(['foo', 'bar']);
47
48 req = httpTesting.expectOne('api/rgw/bucket/foo');
49 req.flush({ name: 'foo' });
50
51 req = httpTesting.expectOne('api/rgw/bucket/bar');
52 req.flush({ name: 'bar' });
53
54 expect(req.request.method).toBe('GET');
55 expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
56 });
57
58 it('should call get', () => {
59 service.get('foo').subscribe();
60 const req = httpTesting.expectOne('api/rgw/bucket/foo');
61 expect(req.request.method).toBe('GET');
62 });
63
64 it('should call create', () => {
65 service.create('foo', 'bar').subscribe();
66 const req = httpTesting.expectOne('api/rgw/bucket?bucket=foo&uid=bar');
67 expect(req.request.method).toBe('POST');
68 });
69
70 it('should call update', () => {
71 service.update('foo', 'bar', 'baz').subscribe();
72 const req = httpTesting.expectOne('api/rgw/bucket/foo?bucket_id=bar&uid=baz');
73 expect(req.request.method).toBe('PUT');
74 });
75
76 it('should call delete, with purgeObjects = true', () => {
77 service.delete('foo').subscribe();
78 const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=true');
79 expect(req.request.method).toBe('DELETE');
80 });
81
82 it('should call delete, with purgeObjects = false', () => {
83 service.delete('foo', false).subscribe();
84 const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=false');
85 expect(req.request.method).toBe('DELETE');
86 });
87
88 it('should call exists', () => {
89 let result;
90 service.exists('foo').subscribe((resp) => {
91 result = resp;
92 });
93 const req = httpTesting.expectOne('api/rgw/bucket');
94 expect(req.request.method).toBe('GET');
95 req.flush(['foo', 'bar']);
96 expect(result).toBe(true);
97 });
98 });