Added bunch more tests

This commit is contained in:
James Titcumb
2026-02-10 12:07:32 +00:00
parent 64bd3595cd
commit 1de7a07f29
3 changed files with 95 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
node_modules/
.idea
.DS_Store
coverage

View File

@@ -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>",

View File

@@ -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');
});
});