]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.spec.ts
add stop-gap to fix compat with CPUs not supporting SSE 4.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / host.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
3
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { HostService } from './host.service';
6
7 describe('HostService', () => {
8 let service: HostService;
9 let httpTesting: HttpTestingController;
10
11 configureTestBed({
12 providers: [HostService],
13 imports: [HttpClientTestingModule]
14 });
15
16 beforeEach(() => {
17 service = TestBed.inject(HostService);
18 httpTesting = TestBed.inject(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', fakeAsync(() => {
30 let result;
31 service.list('true').subscribe((resp) => (result = resp));
32 const req = httpTesting.expectOne('api/host?facts=true');
33 expect(req.request.method).toBe('GET');
34 req.flush(['foo', 'bar']);
35 tick();
36 expect(result).toEqual(['foo', 'bar']);
37 }));
38
39 it('should make a GET request on the devices endpoint when requesting devices', () => {
40 const hostname = 'hostname';
41 service.getDevices(hostname).subscribe();
42 const req = httpTesting.expectOne(`api/host/${hostname}/devices`);
43 expect(req.request.method).toBe('GET');
44 });
45
46 it('should update host', fakeAsync(() => {
47 service.update('mon0', true, ['foo', 'bar'], true, false).subscribe();
48 const req = httpTesting.expectOne('api/host/mon0');
49 expect(req.request.method).toBe('PUT');
50 expect(req.request.body).toEqual({
51 force: false,
52 labels: ['foo', 'bar'],
53 maintenance: true,
54 update_labels: true,
55 drain: false
56 });
57 }));
58
59 it('should test host drain call', fakeAsync(() => {
60 service.update('host0', false, null, false, false, true).subscribe();
61 const req = httpTesting.expectOne('api/host/host0');
62 expect(req.request.method).toBe('PUT');
63 expect(req.request.body).toEqual({
64 force: false,
65 labels: null,
66 maintenance: false,
67 update_labels: false,
68 drain: true
69 });
70 }));
71
72 it('should call getInventory', () => {
73 service.getInventory('host-0').subscribe();
74 let req = httpTesting.expectOne('api/host/host-0/inventory');
75 expect(req.request.method).toBe('GET');
76
77 service.getInventory('host-0', true).subscribe();
78 req = httpTesting.expectOne('api/host/host-0/inventory?refresh=true');
79 expect(req.request.method).toBe('GET');
80 });
81
82 it('should call inventoryList', () => {
83 service.inventoryList().subscribe();
84 let req = httpTesting.expectOne('ui-api/host/inventory');
85 expect(req.request.method).toBe('GET');
86
87 service.inventoryList(true).subscribe();
88 req = httpTesting.expectOne('ui-api/host/inventory?refresh=true');
89 expect(req.request.method).toBe('GET');
90 });
91 });