1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { DebugElement } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { TreeModule } from '@circlon/angular-tree-component';
import { of } from 'rxjs';
import { CrushRuleService } from '~/app/shared/api/crush-rule.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { CrushmapComponent } from './crushmap.component';
describe('CrushmapComponent', () => {
let component: CrushmapComponent;
let fixture: ComponentFixture<CrushmapComponent>;
let debugElement: DebugElement;
let crushRuleService: CrushRuleService;
let crushRuleServiceInfoSpy: jasmine.Spy;
configureTestBed({
imports: [HttpClientTestingModule, TreeModule, SharedModule],
declarations: [CrushmapComponent]
});
beforeEach(() => {
fixture = TestBed.createComponent(CrushmapComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
crushRuleService = TestBed.inject(CrushRuleService);
crushRuleServiceInfoSpy = spyOn(crushRuleService, 'getInfo');
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should display right title', () => {
const span = debugElement.nativeElement.querySelector('.card-header');
expect(span.textContent).toBe('CRUSH map viewer');
});
it('should display "No nodes!" if ceph tree nodes is empty array', fakeAsync(() => {
crushRuleServiceInfoSpy.and.returnValue(of({ nodes: [] }));
fixture.detectChanges();
tick(5000);
expect(crushRuleService.getInfo).toHaveBeenCalled();
expect(component.nodes[0].name).toEqual('No nodes!');
component.ngOnDestroy();
}));
it('should have two root nodes', fakeAsync(() => {
crushRuleServiceInfoSpy.and.returnValue(
of({
nodes: [
{ children: [-2], type: 'root', name: 'default', id: -1 },
{ children: [1, 0, 2], type: 'host', name: 'my-host', id: -2 },
{ status: 'up', type: 'osd', name: 'osd.0', id: 0 },
{ status: 'down', type: 'osd', name: 'osd.1', id: 1 },
{ status: 'up', type: 'osd', name: 'osd.2', id: 2 },
{ children: [-4], type: 'datacenter', name: 'site1', id: -3 },
{ children: [4], type: 'host', name: 'my-host-2', id: -4 },
{ status: 'up', type: 'osd', name: 'osd.0-2', id: 4 }
],
roots: [-1, -3, -6]
})
);
fixture.detectChanges();
tick(10000);
expect(crushRuleService.getInfo).toHaveBeenCalled();
expect(component.nodes).toEqual([
{
cdId: -3,
children: [
{
children: [
{
id: component.nodes[0].children[0].children[0].id,
cdId: 4,
status: 'up',
type: 'osd',
name: 'osd.0-2 (osd)'
}
],
id: component.nodes[0].children[0].id,
cdId: -4,
status: undefined,
type: 'host',
name: 'my-host-2 (host)'
}
],
id: component.nodes[0].id,
status: undefined,
type: 'datacenter',
name: 'site1 (datacenter)'
},
{
children: [
{
children: [
{
id: component.nodes[1].children[0].children[0].id,
cdId: 0,
status: 'up',
type: 'osd',
name: 'osd.0 (osd)'
},
{
id: component.nodes[1].children[0].children[1].id,
cdId: 1,
status: 'down',
type: 'osd',
name: 'osd.1 (osd)'
},
{
id: component.nodes[1].children[0].children[2].id,
cdId: 2,
status: 'up',
type: 'osd',
name: 'osd.2 (osd)'
}
],
id: component.nodes[1].children[0].id,
cdId: -2,
status: undefined,
type: 'host',
name: 'my-host (host)'
}
],
id: component.nodes[1].id,
cdId: -1,
status: undefined,
type: 'root',
name: 'default (root)'
}
]);
component.ngOnDestroy();
}));
});
|