Some improvements
- Use classes - Split buildx/builder modules - Additional tests Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,41 @@
|
||||
import {describe, expect, jest, it} from '@jest/globals';
|
||||
import * as github from '../src/github';
|
||||
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, 'repo').mockImplementation((): Promise<github.ReposGetResponseData> => {
|
||||
return <Promise<github.ReposGetResponseData>>(repoFixture as unknown);
|
||||
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.repo(process.env.GITHUB_TOKEN || '');
|
||||
expect(repo.name).not.toBeNull();
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user