[src/dev/build] implement a getBuildNumber() mock (#74881)

Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Spencer 2020-08-12 11:09:46 -07:00 committed by GitHub
parent 6ee2460ebc
commit c8b63c0b1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 19 deletions

View file

@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export function getBuildNumber() {
return 12345;
}

View file

@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import os from 'os';
import execa from 'execa';
export async function getBuildNumber() {
if (/^win/.test(os.platform())) {
// Windows does not have the wc process and `find /C /V ""` does not consistently work
const log = await execa('git', ['log', '--format="%h"']);
return log.stdout.split('\n').length;
}
const wc = await execa.command('git log --format="%h" | wc -l', {
shell: true,
});
return parseFloat(wc.stdout.trim());
}

View file

@ -20,6 +20,8 @@
import pkg from '../../../../package.json';
import { getVersionInfo } from './version_info';
jest.mock('./get_build_number');
describe('isRelease = true', () => {
it('returns unchanged package.version, build sha, and build number', async () => {
const versionInfo = await getVersionInfo({

View file

@ -17,22 +17,8 @@
* under the License.
*/
import os from 'os';
import execa from 'execa';
async function getBuildNumber() {
if (/^win/.test(os.platform())) {
// Windows does not have the wc process and `find /C /V ""` does not consistently work
const log = await execa('git', ['log', '--format="%h"']);
return log.stdout.split('\n').length;
}
const wc = await execa.command('git log --format="%h" | wc -l', {
shell: true,
});
return parseFloat(wc.stdout.trim());
}
import { getBuildNumber } from './get_build_number';
interface Options {
isRelease: boolean;

View file

@ -26,13 +26,10 @@ import {
import { Config, Platform } from '../../lib';
import { DownloadNodeBuilds } from './download_node_builds_task';
// import * as NodeShasumsNS from '../node_shasums';
// import * as NodeDownloadInfoNS from '../node_download_info';
// import * as DownloadNS from '../../../lib/download';
// import { DownloadNodeBuilds } from '../download_node_builds_task';
jest.mock('./node_shasums');
jest.mock('./node_download_info');
jest.mock('../../lib/download');
jest.mock('../../lib/get_build_number');
expect.addSnapshotSerializer(createAnyInstanceSerializer(ToolingLog));

View file

@ -27,6 +27,7 @@ import { Config } from '../../lib';
import { ExtractNodeBuilds } from './extract_node_builds_task';
jest.mock('../../lib/fs');
jest.mock('../../lib/get_build_number');
const Fs = jest.requireMock('../../lib/fs');

View file

@ -29,6 +29,7 @@ import { VerifyExistingNodeBuilds } from './verify_existing_node_builds_task';
jest.mock('./node_shasums');
jest.mock('./node_download_info');
jest.mock('../../lib/fs');
jest.mock('../../lib/get_build_number');
const { getNodeShasums } = jest.requireMock('./node_shasums');
const { getNodeDownloadInfo } = jest.requireMock('./node_download_info');