test: move git remoteSha api test to integration
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
25
__tests__/git.test.itg.ts
Normal file
25
__tests__/git.test.itg.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2026 actions-toolkit authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
import {Git} from '../src/git.js';
|
||||
|
||||
describe('remoteSha', () => {
|
||||
it('returns sha using github api', async () => {
|
||||
expect(await Git.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head', process.env.GITHUB_TOKEN)).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
|
||||
});
|
||||
});
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
import {Git as GitMocked} from '../src/git.js';
|
||||
import {Git} from '../src/git.js';
|
||||
import {Exec} from '../src/exec.js';
|
||||
import {ExecOutput} from '@actions/exec';
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('context', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
const ctx = await GitMocked.context();
|
||||
const ctx = await Git.context();
|
||||
expect(ctx.ref).toEqual('refs/heads/test');
|
||||
expect(ctx.sha).toEqual('test-sha');
|
||||
});
|
||||
@@ -56,7 +56,7 @@ describe('isInsideWorkTree', () => {
|
||||
it('have been called', async () => {
|
||||
const execSpy = vi.spyOn(Exec, 'getExecOutput');
|
||||
try {
|
||||
await GitMocked.isInsideWorkTree();
|
||||
await Git.isInsideWorkTree();
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
@@ -69,13 +69,7 @@ describe('isInsideWorkTree', () => {
|
||||
|
||||
describe('remoteSha', () => {
|
||||
it('returns sha using git ls-remote', async () => {
|
||||
expect(await GitMocked.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head')).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
|
||||
});
|
||||
it('returns sha using github api', async () => {
|
||||
vi.resetModules();
|
||||
vi.unmock('@actions/github');
|
||||
const {Git} = await import('../src/git.js');
|
||||
expect(await Git.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head', process.env.GITHUB_TOKEN)).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
|
||||
expect(await Git.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head')).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,7 +77,7 @@ describe('remoteURL', () => {
|
||||
it('have been called', async () => {
|
||||
const execSpy = vi.spyOn(Exec, 'getExecOutput');
|
||||
try {
|
||||
await GitMocked.remoteURL();
|
||||
await Git.remoteURL();
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
@@ -113,9 +107,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/test');
|
||||
});
|
||||
|
||||
@@ -137,9 +129,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/tags/8.0.0');
|
||||
});
|
||||
|
||||
@@ -161,9 +151,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/tags/8.0.0');
|
||||
});
|
||||
|
||||
@@ -185,9 +173,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/pull/221/merge');
|
||||
});
|
||||
|
||||
@@ -209,8 +195,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
await expect(GitMocked.ref()).rejects.toThrow('Cannot find detached HEAD ref in "wrong, HEAD, tag: 8.0.0"');
|
||||
await expect(Git.ref()).rejects.toThrow('Cannot find detached HEAD ref in "wrong, HEAD, tag: 8.0.0"');
|
||||
});
|
||||
|
||||
it('returns mocked detached branch ref', async () => {
|
||||
@@ -231,9 +216,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/test');
|
||||
});
|
||||
|
||||
@@ -255,9 +238,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/feature-branch');
|
||||
});
|
||||
|
||||
@@ -282,9 +263,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/main');
|
||||
});
|
||||
|
||||
@@ -309,9 +288,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/main');
|
||||
});
|
||||
|
||||
@@ -339,9 +316,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/heads/feature');
|
||||
});
|
||||
|
||||
@@ -372,9 +347,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/tags/v1.0.0');
|
||||
});
|
||||
|
||||
@@ -405,8 +378,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
await expect(GitMocked.ref()).rejects.toThrow('Cannot infer ref from detached HEAD');
|
||||
await expect(Git.ref()).rejects.toThrow('Cannot infer ref from detached HEAD');
|
||||
});
|
||||
|
||||
it('handles remote ref without branch pattern when inferring from remote', async () => {
|
||||
@@ -433,9 +405,7 @@ describe('ref', () => {
|
||||
exitCode: 0
|
||||
});
|
||||
});
|
||||
|
||||
const ref = await GitMocked.ref();
|
||||
|
||||
const ref = await Git.ref();
|
||||
expect(ref).toEqual('refs/remotes/unusual-format');
|
||||
});
|
||||
});
|
||||
@@ -444,7 +414,7 @@ describe('fullCommit', () => {
|
||||
it('have been called', async () => {
|
||||
const execSpy = vi.spyOn(Exec, 'getExecOutput');
|
||||
try {
|
||||
await GitMocked.fullCommit();
|
||||
await Git.fullCommit();
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
@@ -459,7 +429,7 @@ describe('shortCommit', () => {
|
||||
it('have been called', async () => {
|
||||
const execSpy = vi.spyOn(Exec, 'getExecOutput');
|
||||
try {
|
||||
await GitMocked.shortCommit();
|
||||
await Git.shortCommit();
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
@@ -474,7 +444,7 @@ describe('tag', () => {
|
||||
it('have been called', async () => {
|
||||
const execSpy = vi.spyOn(Exec, 'getExecOutput');
|
||||
try {
|
||||
await GitMocked.tag();
|
||||
await Git.tag();
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
@@ -487,7 +457,7 @@ describe('tag', () => {
|
||||
|
||||
describe('getCommitDate', () => {
|
||||
it('head', async () => {
|
||||
const date = await GitMocked.commitDate('HEAD');
|
||||
await expect(date).toBeInstanceOf(Date);
|
||||
const date = await Git.commitDate('HEAD');
|
||||
expect(date).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user