Skip to content

Commit

Permalink
kbn-es: Support choosing the correct architecture (elastic#61096) (el…
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders authored Mar 24, 2020
1 parent d23a726 commit dbc5e50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/kbn-es/src/artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ async function getArtifactSpecForSnapshot(urlVersion, license, log) {
const manifest = JSON.parse(json);

const platform = process.platform === 'win32' ? 'windows' : process.platform;
const arch = process.arch === 'arm64' ? 'aarch64' : 'x86_64';

const archive = manifest.archives.find(
archive =>
archive.version === desiredVersion &&
archive.platform === platform &&
archive.license === desiredLicense
archive.license === desiredLicense &&
archive.architecture === arch
);

if (!archive) {
Expand Down
24 changes: 22 additions & 2 deletions packages/kbn-es/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const log = new ToolingLog();
let MOCKS;

const PLATFORM = process.platform === 'win32' ? 'windows' : process.platform;
const ARCHITECTURE = process.arch === 'arm64' ? 'aarch64' : 'x86_64';
const MOCK_VERSION = 'test-version';
const MOCK_URL = 'http://127.0.0.1:12345';
const MOCK_FILENAME = 'test-filename';
Expand All @@ -38,13 +39,15 @@ const PERMANENT_SNAPSHOT_BASE_URL =

const createArchive = (params = {}) => {
const license = params.license || 'default';
const architecture = params.architecture || ARCHITECTURE;

return {
license: 'default',
architecture,
version: MOCK_VERSION,
url: MOCK_URL + `/${license}`,
platform: PLATFORM,
filename: MOCK_FILENAME + `.${license}`,
filename: MOCK_FILENAME + `-${architecture}.${license}`,
...params,
};
};
Expand Down Expand Up @@ -77,6 +80,12 @@ beforeEach(() => {
valid: {
archives: [createArchive({ license: 'oss' }), createArchive({ license: 'default' })],
},
multipleArch: {
archives: [
createArchive({ architecture: 'fake_arch', license: 'oss' }),
createArchive({ architecture: ARCHITECTURE, license: 'oss' }),
],
},
};
});

Expand All @@ -95,7 +104,7 @@ const artifactTest = (requestedLicense, expectedLicense, fetchTimesCalled = 1) =
expect(artifact.getUrl()).toEqual(MOCK_URL + `/${expectedLicense}`);
expect(artifact.getChecksumUrl()).toEqual(MOCK_URL + `/${expectedLicense}.sha512`);
expect(artifact.getChecksumType()).toEqual('sha512');
expect(artifact.getFilename()).toEqual(MOCK_FILENAME + `.${expectedLicense}`);
expect(artifact.getFilename()).toEqual(MOCK_FILENAME + `-${ARCHITECTURE}.${expectedLicense}`);
};
};

Expand Down Expand Up @@ -153,6 +162,17 @@ describe('Artifact', () => {
});
});

describe('with snapshots for multiple architectures', () => {
beforeEach(() => {
mockFetch(MOCKS.multipleArch);
});

it('should return artifact metadata for the correct architecture', async () => {
const artifact = await Artifact.getSnapshot('oss', MOCK_VERSION, log);
expect(artifact.getFilename()).toEqual(MOCK_FILENAME + `-${ARCHITECTURE}.oss`);
});
});

describe('with custom snapshot manifest URL', () => {
const CUSTOM_URL = 'http://www.creedthoughts.gov.www/creedthoughts';

Expand Down

0 comments on commit dbc5e50

Please sign in to comment.