Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/dev/build/lib/__mocks__/get_build_number.ts
Original file line number Diff line number Diff line change
@@ -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;
}
34 changes: 34 additions & 0 deletions src/dev/build/lib/get_build_number.ts
Original file line number Diff line number Diff line change
@@ -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());
}
2 changes: 2 additions & 0 deletions src/dev/build/lib/version_info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
16 changes: 1 addition & 15 deletions src/dev/build/lib/version_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/dev/build/tasks/nodejs/download_node_builds_task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down