-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
1,007 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { setFailed } from '@actions/core' | ||
import { run } from '../src/run' | ||
import { fetchRemoteBranches } from '../src/git-util' | ||
import { vi, expect, describe, it, beforeEach } from 'vitest' | ||
|
||
vi.mock('@actions/core', () => ({ | ||
getInput: vi.fn(), | ||
setFailed: vi.fn(), | ||
info: vi.fn() | ||
})) | ||
|
||
vi.mock('../src/git-util', () => ({ | ||
fetchRemoteBranches: vi.fn(), | ||
hasCommitsBetween: vi.fn() | ||
})) | ||
|
||
describe('main function tests', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('should fail if source or target branch is not specified', async () => { | ||
await run({ | ||
srcBranch: '', | ||
targetBranch: 'target-branch', | ||
repoToken: 'dummy-token', | ||
repo: 'test-repo', | ||
owner: 'test-owner' | ||
}) | ||
|
||
expect(setFailed).toHaveBeenCalledWith( | ||
'Source or target branch not specified' | ||
) | ||
}) | ||
|
||
it('should fail if source branch does not exist', async () => { | ||
;(fetchRemoteBranches as any).mockResolvedValue(['valid-branch']) | ||
|
||
await run({ | ||
srcBranch: 'nonexistent-branch', | ||
targetBranch: 'valid-branch', | ||
repoToken: 'dummy-token', | ||
repo: 'test-repo', | ||
owner: 'test-owner' | ||
}) | ||
|
||
expect(setFailed).toHaveBeenCalledWith( | ||
'Source branch nonexistent-branch does not exist' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.