]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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', () => { | |
9f95a23c TL |
65 | service |
66 | .create('foo', 'bar', 'default', 'default-placement', false, 'COMPLIANCE', '10', '0') | |
67 | .subscribe(); | |
68 | const req = httpTesting.expectOne( | |
69 | 'api/rgw/bucket?bucket=foo&uid=bar&zonegroup=default&placement_target=default-placement&lock_enabled=false&lock_mode=COMPLIANCE&lock_retention_period_days=10&lock_retention_period_years=0' | |
70 | ); | |
11fdf7f2 TL |
71 | expect(req.request.method).toBe('POST'); |
72 | }); | |
73 | ||
74 | it('should call update', () => { | |
9f95a23c TL |
75 | service |
76 | .update('foo', 'bar', 'baz', 'Enabled', 'Enabled', '1', '223344', 'GOVERNANCE', '0', '1') | |
77 | .subscribe(); | |
78 | const req = httpTesting.expectOne( | |
79 | 'api/rgw/bucket/foo?bucket_id=bar&uid=baz&versioning_state=Enabled&mfa_delete=Enabled&mfa_token_serial=1&mfa_token_pin=223344&lock_mode=GOVERNANCE&lock_retention_period_days=0&lock_retention_period_years=1' | |
80 | ); | |
11fdf7f2 TL |
81 | expect(req.request.method).toBe('PUT'); |
82 | }); | |
83 | ||
84 | it('should call delete, with purgeObjects = true', () => { | |
85 | service.delete('foo').subscribe(); | |
86 | const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=true'); | |
87 | expect(req.request.method).toBe('DELETE'); | |
88 | }); | |
89 | ||
90 | it('should call delete, with purgeObjects = false', () => { | |
91 | service.delete('foo', false).subscribe(); | |
92 | const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=false'); | |
93 | expect(req.request.method).toBe('DELETE'); | |
94 | }); | |
95 | ||
96 | it('should call exists', () => { | |
97 | let result; | |
98 | service.exists('foo').subscribe((resp) => { | |
99 | result = resp; | |
100 | }); | |
101 | const req = httpTesting.expectOne('api/rgw/bucket'); | |
102 | expect(req.request.method).toBe('GET'); | |
103 | req.flush(['foo', 'bar']); | |
104 | expect(result).toBe(true); | |
105 | }); | |
106 | }); |