mirror of
https://github.com/php/pie-ext-binary-builder.git
synced 2026-03-23 23:22:24 +01:00
Added bunch more tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
node_modules/
|
||||
.idea
|
||||
.DS_Store
|
||||
coverage
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/index.js -o dist --source-map --license licenses.txt",
|
||||
"test": "jest"
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"keywords": ["github", "actions"],
|
||||
"author": "James Titcumb <asgrim@php.net>",
|
||||
|
||||
@@ -181,3 +181,96 @@ describe ('determineExtensionNameFromComposerJson', () => {
|
||||
.toThrow('Invalid extension name: "invalid-ext-name" - must be alphanumeric/underscores only.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineArchitecture', () => {
|
||||
const originalArch = process.arch;
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'arch', {
|
||||
value: originalArch,
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
test('x64', async () => {
|
||||
Object.defineProperty(process, 'arch', { value: 'x64', configurable: true });
|
||||
expect(await action.determineArchitecture()).toBe('x86_64');
|
||||
});
|
||||
|
||||
test('arm64', async () => {
|
||||
Object.defineProperty(process, 'arch', { value: 'arm64', configurable: true });
|
||||
expect(await action.determineArchitecture()).toBe('arm64');
|
||||
});
|
||||
|
||||
test('ia32', async () => {
|
||||
Object.defineProperty(process, 'arch', { value: 'ia32', configurable: true });
|
||||
expect(await action.determineArchitecture()).toBe('x86');
|
||||
});
|
||||
|
||||
test('unsupported architecture', async () => {
|
||||
Object.defineProperty(process, 'arch', { value: 'bloop', configurable: true });
|
||||
await expect(action.determineArchitecture())
|
||||
.rejects
|
||||
.toThrow('Unsupported architecture: bloop');
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineOperatingSystem', () => {
|
||||
const originalPlatform = process.platform;
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
test('linux', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });
|
||||
expect(await action.determineOperatingSystem()).toBe('linux');
|
||||
});
|
||||
|
||||
test('darwin', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
|
||||
expect(await action.determineOperatingSystem()).toBe('darwin');
|
||||
});
|
||||
|
||||
test('win32', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
|
||||
await expect(action.determineOperatingSystem())
|
||||
.rejects
|
||||
.toThrow('Unsupported operating system: win32');
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineLibcFlavour', () => {
|
||||
const originalPlatform = process.platform;
|
||||
|
||||
beforeEach(() => {
|
||||
exec.getExecOutput.mockReset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
test('osx uses bsdlibc', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
|
||||
await expect(action.determineLibcFlavour()).resolves.toBe('bsdlibc');
|
||||
});
|
||||
|
||||
test('musl detected', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });
|
||||
exec.getExecOutput.mockResolvedValue({ stdout: 'musl libc (1.2.4)\n', exitCode: 0 });
|
||||
await expect(action.determineLibcFlavour()).resolves.toBe('musl');
|
||||
});
|
||||
|
||||
test('otherwise glibc', async () => {
|
||||
Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });
|
||||
exec.getExecOutput.mockResolvedValue({ stdout: 'ldd (GNU libc) 2.31\n', exitCode: 0 });
|
||||
await expect(action.determineLibcFlavour()).resolves.toBe('glibc');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user