]>
Commit | Line | Data |
---|---|---|
aee94f69 TL |
1 | import { UpgradeService } from './upgrade.service'; |
2 | import { configureTestBed } from '~/testing/unit-test-helper'; | |
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
4 | import { TestBed } from '@angular/core/testing'; | |
5 | import { SummaryService } from '../services/summary.service'; | |
6 | import { BehaviorSubject } from 'rxjs'; | |
7 | ||
8 | export class SummaryServiceMock { | |
9 | summaryDataSource = new BehaviorSubject({ | |
10 | version: | |
11 | 'ceph version 18.1.3-12222-gcd0cd7cb ' + | |
12 | '(b8193bb4cda16ccc5b028c3e1df62bc72350a15d) reef (dev)' | |
13 | }); | |
14 | summaryData$ = this.summaryDataSource.asObservable(); | |
15 | ||
16 | subscribe(call: any) { | |
17 | return this.summaryData$.subscribe(call); | |
18 | } | |
19 | } | |
20 | ||
21 | describe('UpgradeService', () => { | |
22 | let service: UpgradeService; | |
23 | let httpTesting: HttpTestingController; | |
24 | ||
25 | configureTestBed({ | |
26 | imports: [HttpClientTestingModule], | |
27 | providers: [UpgradeService, { provide: SummaryService, useClass: SummaryServiceMock }] | |
28 | }); | |
29 | ||
30 | beforeEach(() => { | |
31 | service = TestBed.inject(UpgradeService); | |
32 | httpTesting = TestBed.inject(HttpTestingController); | |
33 | }); | |
34 | ||
35 | afterEach(() => { | |
36 | httpTesting.verify(); | |
37 | }); | |
38 | ||
39 | it('should be created', () => { | |
40 | expect(service).toBeTruthy(); | |
41 | }); | |
42 | ||
43 | it('should call upgrade list', () => { | |
44 | service.list().subscribe(); | |
45 | const req = httpTesting.expectOne('api/cluster/upgrade'); | |
46 | expect(req.request.method).toBe('GET'); | |
47 | }); | |
48 | ||
49 | it('should not show any version if the registry versions are older than the cluster version', () => { | |
50 | const upgradeInfoPayload = { | |
51 | image: 'quay.io/ceph-test/ceph', | |
52 | registry: 'quay.io', | |
53 | versions: ['18.1.0', '18.1.1', '18.1.2'] | |
54 | }; | |
55 | const expectedVersions: string[] = []; | |
56 | expect(service.versionAvailableForUpgrades(upgradeInfoPayload).versions).toEqual( | |
57 | expectedVersions | |
58 | ); | |
59 | }); | |
60 | ||
61 | it('should start the upgrade', () => { | |
62 | service.start('18.1.0').subscribe(); | |
63 | const req = httpTesting.expectOne('api/cluster/upgrade/start'); | |
64 | expect(req.request.method).toBe('POST'); | |
65 | expect(req.request.body).toEqual({ version: '18.1.0' }); | |
66 | }); | |
67 | }); |