2020-09-14 14:24:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
import {SemVer} from 'semver';
|
|
|
|
|
2021-04-08 15:34:55 -04:00
|
|
|
import {ReleaseTrain} from '../../release/versioning';
|
2020-09-14 14:24:15 -04:00
|
|
|
import * as versioning from '../../release/versioning/active-release-trains';
|
|
|
|
import * as console from '../../utils/console';
|
2021-04-08 15:34:55 -04:00
|
|
|
import {installVirtualGitClientSpies, mockNgDevConfig} from '../../utils/testing';
|
2020-09-14 14:24:15 -04:00
|
|
|
|
|
|
|
import {CiModule} from './ci';
|
|
|
|
|
|
|
|
describe('CiModule', () => {
|
|
|
|
let fetchActiveReleaseTrainsSpy: jasmine.Spy;
|
|
|
|
let getBranchStatusFromCiSpy: jasmine.Spy;
|
|
|
|
let infoSpy: jasmine.Spy;
|
|
|
|
let debugSpy: jasmine.Spy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-04-08 15:34:55 -04:00
|
|
|
installVirtualGitClientSpies();
|
2020-09-14 14:24:15 -04:00
|
|
|
fetchActiveReleaseTrainsSpy = spyOn(versioning, 'fetchActiveReleaseTrains');
|
|
|
|
getBranchStatusFromCiSpy = spyOn(CiModule.prototype, 'getBranchStatusFromCi' as any);
|
|
|
|
infoSpy = spyOn(console, 'info');
|
|
|
|
debugSpy = spyOn(console, 'debug');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getting data for active trains', () => {
|
|
|
|
it('handles active rc train', async () => {
|
|
|
|
const trains = buildMockActiveReleaseTrains(true);
|
|
|
|
fetchActiveReleaseTrainsSpy.and.resolveTo(trains);
|
2021-04-08 15:34:55 -04:00
|
|
|
const module = new CiModule({caretaker: {}, ...mockNgDevConfig});
|
2020-09-14 14:24:15 -04:00
|
|
|
await module.data;
|
|
|
|
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledWith(trains.releaseCandidate.branchName);
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledWith(trains.latest.branchName);
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledWith(trains.next.branchName);
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledTimes(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles an inactive rc train', async () => {
|
|
|
|
const trains = buildMockActiveReleaseTrains(false);
|
|
|
|
fetchActiveReleaseTrainsSpy.and.resolveTo(trains);
|
2021-04-08 15:34:55 -04:00
|
|
|
const module = new CiModule({caretaker: {}, ...mockNgDevConfig});
|
2020-09-14 14:24:15 -04:00
|
|
|
await module.data;
|
|
|
|
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledWith(trains.latest.branchName);
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledWith(trains.next.branchName);
|
|
|
|
expect(getBranchStatusFromCiSpy).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregates information into a useful structure', async () => {
|
|
|
|
const trains = buildMockActiveReleaseTrains(false);
|
|
|
|
fetchActiveReleaseTrainsSpy.and.resolveTo(trains);
|
|
|
|
getBranchStatusFromCiSpy.and.returnValue('success');
|
2021-04-08 15:34:55 -04:00
|
|
|
const module = new CiModule({caretaker: {}, ...mockNgDevConfig});
|
2020-09-14 14:24:15 -04:00
|
|
|
const data = await module.data;
|
|
|
|
|
|
|
|
expect(data[0]).toEqual(
|
|
|
|
{active: false, name: 'releaseCandidate', label: '', status: 'not found'});
|
|
|
|
expect(data[1]).toEqual({
|
|
|
|
active: true,
|
|
|
|
name: 'latest-branch',
|
|
|
|
label: 'latest (latest-branch)',
|
|
|
|
status: 'success',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('prints the data retrieved', async () => {
|
|
|
|
const fakeData = Promise.resolve([
|
|
|
|
{
|
|
|
|
active: true,
|
|
|
|
name: 'name0',
|
|
|
|
label: 'label0',
|
|
|
|
status: 'success',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
active: false,
|
|
|
|
name: 'name1',
|
|
|
|
label: 'label1',
|
|
|
|
status: 'failed',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
fetchActiveReleaseTrainsSpy.and.resolveTo([]);
|
|
|
|
|
2021-04-08 15:34:55 -04:00
|
|
|
const module = new CiModule({caretaker: {}, ...mockNgDevConfig});
|
2020-09-14 14:24:15 -04:00
|
|
|
Object.defineProperty(module, 'data', {value: fakeData});
|
|
|
|
|
|
|
|
await module.printToTerminal();
|
|
|
|
|
|
|
|
expect(debugSpy).toHaveBeenCalledWith('No active release train for name1');
|
|
|
|
expect(infoSpy).toHaveBeenCalledWith('label0 ✅');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Build a mock set of ActiveReleaseTrains. */
|
|
|
|
function buildMockActiveReleaseTrains(withRc: false): versioning.ActiveReleaseTrains&
|
|
|
|
{releaseCandidate: null};
|
|
|
|
function buildMockActiveReleaseTrains(withRc: true): versioning.ActiveReleaseTrains&
|
|
|
|
{releaseCandidate: ReleaseTrain};
|
|
|
|
function buildMockActiveReleaseTrains(withRc: boolean): versioning.ActiveReleaseTrains {
|
|
|
|
const baseResult = {
|
|
|
|
isMajor: false,
|
|
|
|
version: new SemVer('0.0.0'),
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
releaseCandidate: withRc ? {branchName: 'rc-branch', ...baseResult} : null,
|
|
|
|
latest: {branchName: 'latest-branch', ...baseResult},
|
|
|
|
next: {branchName: 'next-branch', ...baseResult}
|
|
|
|
};
|
|
|
|
}
|