--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+
+import { AuthStorageService } from '../services/auth-storage.service';
+
+import { configureTestBed } from '../unit-test-helper';
+import { AuthService } from './auth.service';
+
+describe('AuthService', () => {
+ let service: AuthService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [AuthService, AuthStorageService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(AuthService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it(
+ 'should login and save the user',
+ fakeAsync(() => {
+ const fakeCredentials = { username: 'foo', password: 'bar' };
+ service.login(<any>fakeCredentials);
+ const req = httpTesting.expectOne('api/auth');
+ expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual(fakeCredentials);
+ req.flush(fakeCredentials);
+ tick();
+ expect(localStorage.getItem('dashboard_username')).toBe('foo');
+ })
+ );
+
+ it(
+ 'should logout and remove the user',
+ fakeAsync(() => {
+ service.logout();
+ const req = httpTesting.expectOne('api/auth');
+ expect(req.request.method).toBe('DELETE');
+ req.flush({ username: 'foo' });
+ tick();
+ expect(localStorage.getItem('dashboard_username')).toBe(null);
+ })
+ );
+});
-import { HttpClientModule } from '@angular/common/http';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { CephfsService } from './cephfs.service';
describe('CephfsService', () => {
+ let service: CephfsService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
- imports: [HttpClientModule],
+ imports: [HttpClientTestingModule],
providers: [CephfsService]
});
- it(
- 'should be created',
- inject([CephfsService], (service: CephfsService) => {
- expect(service).toBeTruthy();
- })
- );
+ beforeEach(() => {
+ service = TestBed.get(CephfsService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call list', () => {
+ service.list().subscribe();
+ const req = httpTesting.expectOne('api/cephfs');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call getCephfs', () => {
+ service.getCephfs(1).subscribe();
+ const req = httpTesting.expectOne('api/cephfs/1');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call getClients', () => {
+ service.getClients(1).subscribe();
+ const req = httpTesting.expectOne('api/cephfs/1/clients');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call getMdsCounters', () => {
+ service.getMdsCounters(1).subscribe();
+ const req = httpTesting.expectOne('api/cephfs/1/mds_counters');
+ expect(req.request.method).toBe('GET');
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { ConfigurationService } from './configuration.service';
describe('ConfigurationService', () => {
+ let service: ConfigurationService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [ConfigurationService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(ConfigurationService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([ConfigurationService], (service: ConfigurationService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call getConfigData', () => {
+ service.getConfigData().subscribe();
+ const req = httpTesting.expectOne('api/cluster_conf/');
+ expect(req.request.method).toBe('GET');
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { DashboardService } from './dashboard.service';
describe('DashboardService', () => {
+ let service: DashboardService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [DashboardService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(DashboardService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([DashboardService], (service: DashboardService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call getHealth', () => {
+ service.getHealth().subscribe();
+ const req = httpTesting.expectOne('api/dashboard/health');
+ expect(req.request.method).toBe('GET');
+ });
});
--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+
+import { configureTestBed } from '../unit-test-helper';
+import { HostService } from './host.service';
+
+describe('HostService', () => {
+ let service: HostService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [HostService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(HostService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it(
+ 'should call list',
+ fakeAsync(() => {
+ let result;
+ service.list().then((resp) => (result = resp));
+ const req = httpTesting.expectOne('api/host');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo', 'bar']);
+ tick();
+ expect(result).toEqual(['foo', 'bar']);
+ })
+ );
+});
--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
+
+import { configureTestBed } from '../unit-test-helper';
+import { LoggingService } from './logging.service';
+
+describe('LoggingService', () => {
+ let service: LoggingService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [LoggingService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(LoggingService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call jsError', () => {
+ service.jsError('foo', 'bar', 'baz').subscribe();
+ const req = httpTesting.expectOne('ui-api/logging/js-error');
+ expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual({
+ url: 'foo',
+ message: 'bar',
+ stack: 'baz'
+ });
+ });
+});
providedIn: ApiModule
})
export class LoggingService {
-
- constructor(private http: HttpClient) {
- }
+ constructor(private http: HttpClient) {}
jsError(url, message, stack) {
const request = {
};
return this.http.post('ui-api/logging/js-error', request);
}
-
}
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { MonitorService } from './monitor.service';
describe('MonitorService', () => {
+ let service: MonitorService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [MonitorService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(MonitorService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([MonitorService], (service: MonitorService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call getMonitor', () => {
+ service.getMonitor().subscribe();
+ const req = httpTesting.expectOne('api/monitor');
+ expect(req.request.method).toBe('GET');
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { OsdService } from './osd.service';
describe('OsdService', () => {
+ let service: OsdService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [OsdService],
- imports: [HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(OsdService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([OsdService], (service: OsdService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call getList', () => {
+ service.getList().subscribe();
+ const req = httpTesting.expectOne('api/osd');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call getDetails', () => {
+ service.getDetails(1).subscribe();
+ const req = httpTesting.expectOne('api/osd/1');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call scrub, with deep=true', () => {
+ service.scrub('foo', true).subscribe();
+ const req = httpTesting.expectOne('api/osd/foo/scrub?deep=true');
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call scrub, with deep=false', () => {
+ service.scrub('foo', false).subscribe();
+ const req = httpTesting.expectOne('api/osd/foo/scrub?deep=false');
+ expect(req.request.method).toBe('POST');
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
-
-import { BsDropdownModule } from 'ngx-bootstrap';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { PerformanceCounterService } from './performance-counter.service';
describe('PerformanceCounterService', () => {
+ let service: PerformanceCounterService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [PerformanceCounterService],
- imports: [HttpClientTestingModule, BsDropdownModule.forRoot(), HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(PerformanceCounterService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
});
- it(
- 'should be created',
- inject([PerformanceCounterService], (service: PerformanceCounterService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call list', () => {
+ service.list().subscribe();
+ const req = httpTesting.expectOne('api/perf_counters');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call get', () => {
+ let result;
+ service.get('foo', '1').subscribe((resp) => {
+ result = resp;
+ });
+ const req = httpTesting.expectOne('api/perf_counters/foo/1');
+ expect(req.request.method).toBe('GET');
+ req.flush({ counters: [{ foo: 'bar' }] });
+ expect(result).toEqual([{ foo: 'bar' }]);
+ });
});
--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+
+import { configureTestBed } from '../unit-test-helper';
+import { PoolService } from './pool.service';
+
+describe('PoolService', () => {
+ let service: PoolService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [PoolService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(PoolService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call getList', () => {
+ service.getList().subscribe();
+ const req = httpTesting.expectOne('api/pool');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it(
+ 'should call list without parameter',
+ fakeAsync(() => {
+ let result;
+ service.list().then((resp) => (result = resp));
+ const req = httpTesting.expectOne('api/pool?attrs=');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo', 'bar']);
+ tick();
+ expect(result).toEqual(['foo', 'bar']);
+ })
+ );
+
+ it(
+ 'should call list with a list',
+ fakeAsync(() => {
+ let result;
+ service.list(['foo']).then((resp) => (result = resp));
+ const req = httpTesting.expectOne('api/pool?attrs=foo');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo', 'bar']);
+ tick();
+ expect(result).toEqual(['foo', 'bar']);
+ })
+ );
+});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { RbdMirroringService } from './rbd-mirroring.service';
describe('RbdMirroringService', () => {
+ let service: RbdMirroringService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [RbdMirroringService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(RbdMirroringService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([RbdMirroringService], (service: RbdMirroringService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call get', () => {
+ service.get().subscribe();
+ const req = httpTesting.expectOne('api/rbdmirror');
+ expect(req.request.method).toBe('GET');
+ });
});
--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
+
+import { configureTestBed } from '../unit-test-helper';
+import { RbdService } from './rbd.service';
+
+describe('RbdService', () => {
+ let service: RbdService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [RbdService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(RbdService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call create', () => {
+ service.create('foo').subscribe();
+ const req = httpTesting.expectOne('api/block/image');
+ expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual('foo');
+ });
+
+ it('should call delete', () => {
+ service.delete('poolName', 'rbdName').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call update', () => {
+ service.update('poolName', 'rbdName', 'foo').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName');
+ expect(req.request.body).toEqual('foo');
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call get', () => {
+ service.get('poolName', 'rbdName').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call list', () => {
+ service.list().subscribe();
+ const req = httpTesting.expectOne('api/block/image');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call copy', () => {
+ service.copy('poolName', 'rbdName', 'foo').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/copy');
+ expect(req.request.body).toEqual('foo');
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call flatten', () => {
+ service.flatten('poolName', 'rbdName').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/flatten');
+ expect(req.request.body).toEqual(null);
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call defaultFeatures', () => {
+ service.defaultFeatures().subscribe();
+ const req = httpTesting.expectOne('api/block/image/default_features');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call createSnapshot', () => {
+ service.createSnapshot('poolName', 'rbdName', 'snapshotName').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/snap');
+ expect(req.request.body).toEqual({
+ snapshot_name: 'snapshotName'
+ });
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call renameSnapshot', () => {
+ service.renameSnapshot('poolName', 'rbdName', 'snapshotName', 'foo').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/snap/snapshotName');
+ expect(req.request.body).toEqual({
+ new_snap_name: 'foo'
+ });
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call protectSnapshot', () => {
+ service.protectSnapshot('poolName', 'rbdName', 'snapshotName', true).subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/snap/snapshotName');
+ expect(req.request.body).toEqual({
+ is_protected: true
+ });
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call rollbackSnapshot', () => {
+ service.rollbackSnapshot('poolName', 'rbdName', 'snapshotName').subscribe();
+ const req = httpTesting.expectOne(
+ 'api/block/image/poolName/rbdName/snap/snapshotName/rollback'
+ );
+ expect(req.request.body).toEqual(null);
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call cloneSnapshot', () => {
+ service.cloneSnapshot('poolName', 'rbdName', 'snapshotName', null).subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/snap/snapshotName/clone');
+ expect(req.request.body).toEqual(null);
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call deleteSnapshot', () => {
+ service.deleteSnapshot('poolName', 'rbdName', 'snapshotName').subscribe();
+ const req = httpTesting.expectOne('api/block/image/poolName/rbdName/snap/snapshotName');
+ expect(req.request.method).toBe('DELETE');
+ });
+});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { RgwBucketService } from './rgw-bucket.service';
describe('RgwBucketService', () => {
+ let service: RgwBucketService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [RgwBucketService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(RgwBucketService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
});
- it(
- 'should be created',
- inject([RgwBucketService], (service: RgwBucketService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should call list, with enumerate returning empty', () => {
+ let result;
+ service.list().subscribe((resp) => {
+ result = resp;
+ });
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket');
+ req.flush([]);
+ expect(req.request.method).toBe('GET');
+ expect(result).toEqual([]);
+ });
+
+ it('should call list, with enumerate returning 2 elements', () => {
+ let result;
+ service.list().subscribe((resp) => {
+ result = resp;
+ });
+ let req = httpTesting.expectOne('/api/rgw/proxy/bucket');
+ req.flush(['foo', 'bar']);
+
+ req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=foo');
+ req.flush({ name: 'foo' });
+
+ req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=bar');
+ req.flush({ name: 'bar' });
+
+ expect(req.request.method).toBe('GET');
+ expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
+ });
+
+ it('should call get', () => {
+ service.get('foo').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=foo');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call create', () => {
+ service.create('foo', 'bar').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/bucket');
+ expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual({
+ bucket: 'foo',
+ uid: 'bar'
+ });
+ });
+
+ it('should call update', () => {
+ service.update('foo', 'bar', 'baz').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=bar&bucket-id=foo&uid=baz');
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call delete, with purgeObjects = true', () => {
+ service.delete('foo').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=foo&purge-objects=true');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call delete, with purgeObjects = false', () => {
+ service.delete('foo', false).subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket?bucket=foo&purge-objects=false');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call exists', () => {
+ let result;
+ service.exists('foo').subscribe((resp) => {
+ result = resp;
+ });
+ const req = httpTesting.expectOne('/api/rgw/proxy/bucket');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo', 'bar']);
+ expect(result).toBe(true);
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '../unit-test-helper';
import { RgwDaemonService } from './rgw-daemon.service';
describe('RgwDaemonService', () => {
+ let service: RgwDaemonService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
providers: [RgwDaemonService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(RgwDaemonService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
});
- it(
- 'should be created',
- inject([RgwDaemonService], (service: RgwDaemonService) => {
- expect(service).toBeTruthy();
- })
- );
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call list', () => {
+ service.list().subscribe();
+ const req = httpTesting.expectOne('api/rgw/daemon');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call get', () => {
+ service.get('foo').subscribe();
+ const req = httpTesting.expectOne('api/rgw/daemon/foo');
+ expect(req.request.method).toBe('GET');
+ });
});
-import { HttpClientModule } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { inject } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
+
+import { of as observableOf } from 'rxjs';
import { configureTestBed } from '../unit-test-helper';
import { RgwUserService } from './rgw-user.service';
describe('RgwUserService', () => {
+ let service: RgwUserService;
+ let httpTesting: HttpTestingController;
+
configureTestBed({
- providers: [RgwUserService],
- imports: [HttpClientTestingModule, HttpClientModule]
+ imports: [HttpClientTestingModule],
+ providers: [RgwUserService]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(RgwUserService);
+ httpTesting = TestBed.get(HttpTestingController);
});
- it(
- 'should be created',
- inject([RgwUserService], (service: RgwUserService) => {
- expect(service).toBeTruthy();
- })
- );
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('should call list with empty result', () => {
+ let result;
+ service.list().subscribe((resp) => {
+ result = resp;
+ });
+ const req = httpTesting.expectOne('/api/rgw/proxy/metadata/user');
+ expect(req.request.method).toBe('GET');
+ req.flush([]);
+ expect(result).toEqual([]);
+ });
+
+ it('should call list with result', () => {
+ let result;
+ service.list().subscribe((resp) => {
+ result = resp;
+ });
+
+ let req = httpTesting.expectOne('/api/rgw/proxy/metadata/user');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo', 'bar']);
+
+ req = httpTesting.expectOne('/api/rgw/proxy/user?uid=foo');
+ expect(req.request.method).toBe('GET');
+ req.flush({ name: 'foo' });
+
+ req = httpTesting.expectOne('/api/rgw/proxy/user?uid=bar');
+ expect(req.request.method).toBe('GET');
+ req.flush({ name: 'bar' });
+
+ expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
+ });
+
+ it('should call enumerate', () => {
+ service.enumerate().subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/metadata/user');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call get', () => {
+ service.get('foo').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?uid=foo');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call getQuota', () => {
+ service.getQuota('foo').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?quota&uid=foo');
+ expect(req.request.method).toBe('GET');
+ });
+
+ it('should call put', () => {
+ service.put({ foo: 'bar' }).subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?foo=bar');
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call putQuota', () => {
+ service.putQuota({ foo: 'bar' }).subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?quota&foo=bar');
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call post', () => {
+ service.post({ foo: 'bar' }).subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?foo=bar');
+ expect(req.request.method).toBe('POST');
+ });
+
+ it('should call delete', () => {
+ service.delete('foo').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?uid=foo');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call addSubuser with unrecognized permission', () => {
+ service.addSubuser('foo', 'bar', 'baz', null, true).subscribe();
+ const req = httpTesting.expectOne(
+ '/api/rgw/proxy/user?uid=foo&subuser=bar&key-type=swift&access=baz&generate-secret=true'
+ );
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call addSubuser with mapped permission', () => {
+ service.addSubuser('foo', 'bar', 'full-control', 'baz', false).subscribe();
+ const req = httpTesting.expectOne(
+ '/api/rgw/proxy/user?uid=foo&subuser=bar&key-type=swift&access=full&secret-key=baz'
+ );
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call deleteSubuser', () => {
+ service.deleteSubuser('foo', 'bar').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?uid=foo&subuser=bar&purge-keys=true');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call addCapability', () => {
+ service.addCapability('foo', 'bar', 'baz').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?caps&uid=foo&user-caps=bar=baz');
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call deleteCapability', () => {
+ service.deleteCapability('foo', 'bar', 'baz').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?caps&uid=foo&user-caps=bar=baz');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call addS3Key, with generateKey true', () => {
+ service.addS3Key('1', 'foo', 'bar', 'baz', true).subscribe();
+ const req = httpTesting.expectOne(
+ '/api/rgw/proxy/user?key&uid=1&key-type=s3&generate-key=true&subuser=foo'
+ );
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call addS3Key, with generateKey false', () => {
+ service.addS3Key('1', 'foo', 'bar', 'baz', false).subscribe();
+ const req = httpTesting.expectOne(
+ '/api/rgw/proxy/user?key' +
+ '&uid=1&key-type=s3&generate-key=false&access-key=bar&secret-key=baz&subuser=foo'
+ );
+ expect(req.request.method).toBe('PUT');
+ });
+
+ it('should call deleteS3Key', () => {
+ service.deleteS3Key('foo', 'bar').subscribe();
+ const req = httpTesting.expectOne('/api/rgw/proxy/user?key&uid=foo&key-type=s3&access-key=bar');
+ expect(req.request.method).toBe('DELETE');
+ });
+
+ it('should call exists with an existent uid', () => {
+ spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
+ let result;
+ service.exists('foo').subscribe((res) => {
+ result = res;
+ });
+ expect(result).toBe(true);
+ });
+
+ it('should call exists with a non existent uid', () => {
+ spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
+ let result;
+ service.exists('baz').subscribe((res) => {
+ result = res;
+ });
+ expect(result).toBe(false);
+ });
});
--- /dev/null
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+
+import { configureTestBed } from '../unit-test-helper';
+import { TcmuIscsiService } from './tcmu-iscsi.service';
+
+describe('TcmuIscsiService', () => {
+ let service: TcmuIscsiService;
+ let httpTesting: HttpTestingController;
+
+ configureTestBed({
+ providers: [TcmuIscsiService],
+ imports: [HttpClientTestingModule]
+ });
+
+ beforeEach(() => {
+ service = TestBed.get(TcmuIscsiService);
+ httpTesting = TestBed.get(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpTesting.verify();
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it(
+ 'should call tcmuiscsi',
+ fakeAsync(() => {
+ let result;
+ service.tcmuiscsi().then((resp) => {
+ result = resp;
+ });
+ const req = httpTesting.expectOne('api/tcmuiscsi');
+ expect(req.request.method).toBe('GET');
+ req.flush(['foo']);
+ tick();
+ expect(result).toEqual(['foo']);
+ })
+ );
+});