Merge pull request #936 from crazy-max/oci-defaultPlatform

oci: defaultPlatform function
This commit is contained in:
CrazyMax
2026-01-14 12:01:47 +01:00
committed by GitHub
2 changed files with 71 additions and 1 deletions

View File

@@ -14,14 +14,17 @@
* limitations under the License.
*/
import {afterEach, describe, expect, test} from '@jest/globals';
import {afterEach, describe, expect, jest, test} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {OCI} from '../../src/oci/oci';
import {Platform} from '../../src/types/oci/descriptor';
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'oci-oci-'));
@@ -29,6 +32,25 @@ afterEach(function () {
rimraf.sync(tmpDir);
});
describe('defaultPlatform', () => {
test.each([
['win32', 'x64', {architecture: 'amd64', os: 'windows'}],
['win32', 'arm64', {architecture: 'arm64', os: 'windows'}],
['darwin', 'x64', {architecture: 'amd64', os: 'darwin'}],
['darwin', 'arm64', {architecture: 'arm64', os: 'darwin'}],
['linux', 'ia32', {architecture: '386', os: 'linux'}],
['linux', 'x64', {architecture: 'amd64', os: 'linux'}],
['linux', 'arm64', {architecture: 'arm64', os: 'linux'}],
['linux', 'ppc64', {architecture: 'ppc64le', os: 'linux'}],
['linux', 's390x', {architecture: 's390x', os: 'linux'}]
])('default platform for %s/%s', async (os: string, arch: string, expected: Platform) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
const res = OCI.defaultPlatform();
expect(res).toEqual(expected);
});
});
describe('loadArchive', () => {
// prettier-ignore
test.each(fs.readdirSync(path.join(fixturesDir, 'oci-archive')).filter(file => {