mirror of
https://code.forgejo.org/docker/build-push-action.git
synced 2025-08-11 17:10:54 +00:00
- Rename reportBuildMetrics to reportBuildStart for clarity - Check if builder name contains 'blacksmith' before reporting - Log warning when not using a Blacksmith builder - Skip build start and completion reporting for non-Blacksmith builders - Update tests to reflect function rename 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import * as core from '@actions/core';
|
|
import * as main from '../main';
|
|
import * as reporter from '../reporter';
|
|
import {getDockerfilePath} from '../context';
|
|
|
|
jest.mock('@actions/core', () => ({
|
|
debug: jest.fn(),
|
|
warning: jest.fn(),
|
|
info: jest.fn(),
|
|
saveState: jest.fn(),
|
|
getState: jest.fn(),
|
|
setOutput: jest.fn(),
|
|
setFailed: jest.fn(),
|
|
error: jest.fn()
|
|
}));
|
|
|
|
jest.mock('../context', () => ({
|
|
getDockerfilePath: jest.fn(),
|
|
Inputs: jest.fn()
|
|
}));
|
|
|
|
jest.mock('../reporter', () => {
|
|
const actual = jest.requireActual('../reporter');
|
|
return {
|
|
...actual,
|
|
reportBuildPushActionFailure: jest.fn().mockResolvedValue(undefined),
|
|
reportBuild: jest.fn()
|
|
};
|
|
});
|
|
|
|
describe('reportBuildStart', () => {
|
|
let mockInputs;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mockInputs = {
|
|
setupOnly: false,
|
|
platforms: []
|
|
};
|
|
});
|
|
|
|
test('should handle missing dockerfile path', async () => {
|
|
(getDockerfilePath as jest.Mock).mockReturnValue(null);
|
|
|
|
const result = await main.reportBuildStart(mockInputs);
|
|
|
|
expect(result).toBeNull();
|
|
expect(core.warning).toHaveBeenCalledWith('Error when reporting build metrics: Failed to resolve dockerfile path');
|
|
expect(reporter.reportBuildPushActionFailure).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should successfully report build start', async () => {
|
|
const mockBuildId = 'test-build-id';
|
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
|
(reporter.reportBuild as jest.Mock).mockResolvedValue({docker_build_id: mockBuildId});
|
|
|
|
const result = await main.reportBuildStart(mockInputs);
|
|
|
|
expect(result).toBe(mockBuildId);
|
|
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
|
expect(reporter.reportBuildPushActionFailure).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should handle reportBuildStart returning null', async () => {
|
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
|
(reporter.reportBuild as jest.Mock).mockResolvedValue(null);
|
|
|
|
const result = await main.reportBuildStart(mockInputs);
|
|
|
|
expect(result).toBeNull();
|
|
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
|
expect(reporter.reportBuildPushActionFailure).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should handle error in reportBuildStart', async () => {
|
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
|
(reporter.reportBuild as jest.Mock).mockRejectedValue(new Error('API error'));
|
|
|
|
const result = await main.reportBuildStart(mockInputs);
|
|
|
|
expect(result).toBeNull();
|
|
expect(core.warning).toHaveBeenCalledWith('Error reporting build start: API error');
|
|
expect(reporter.reportBuildPushActionFailure).not.toHaveBeenCalled();
|
|
});
|
|
});
|