mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 11:36:10 +08:00
aae4a2d7bc
- Use classes - Split buildx/builder modules - Additional tests Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import {describe, expect, jest, it} from '@jest/globals';
|
|
import {Context} from '@actions/github/lib/context';
|
|
|
|
import {GitHub, Payload, ReposGetResponseData} from '../src/github';
|
|
|
|
jest.spyOn(GitHub.prototype, 'context').mockImplementation((): Context => {
|
|
return new Context();
|
|
});
|
|
|
|
import * as repoFixture from './fixtures/repo.json';
|
|
jest.spyOn(GitHub.prototype, 'repo').mockImplementation((): Promise<ReposGetResponseData> => {
|
|
return <Promise<ReposGetResponseData>>(repoFixture as unknown);
|
|
});
|
|
|
|
import * as payloadFixture from './fixtures/github-payload.json';
|
|
jest.spyOn(GitHub.prototype as any, 'payload').mockImplementation((): Promise<Payload> => {
|
|
return <Promise<Payload>>(payloadFixture as unknown);
|
|
});
|
|
jest.spyOn(GitHub.prototype as any, 'ref').mockImplementation((): string => {
|
|
return 'refs/heads/master';
|
|
});
|
|
|
|
describe('gitContext', () => {
|
|
it('returns refs/heads/master', async () => {
|
|
expect(GitHub.getInstance().gitContext()).toEqual('https://github.com/docker/test-docker-action.git#refs/heads/master');
|
|
});
|
|
});
|
|
|
|
describe('repo', () => {
|
|
it('returns GitHub repository', async () => {
|
|
const repo = await GitHub.getInstance().repo(process.env.GITHUB_TOKEN || '');
|
|
expect(repo.name).toEqual('Hello-World');
|
|
});
|
|
});
|
|
|
|
describe('fromPayload', () => {
|
|
it('returns repository name from payload', async () => {
|
|
const repoName = await GitHub.getInstance().fromPayload('repository.name');
|
|
expect(repoName).toEqual('test-docker-action');
|
|
});
|
|
});
|