generated from actions/typescript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
author
committed
Dec 12, 2024
1 parent
9a1cbac
commit 2d961e8
Showing
1 changed file
with
69 additions
and
0 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,69 @@ | ||
from pytest_mock import MockerFixture | ||
|
||
|
||
async def test_checkout_branch(mocker: MockerFixture): | ||
from src.plugins.github.handlers.git import GitHandler | ||
|
||
mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command") | ||
|
||
git_handler = GitHandler() | ||
git_handler.checkout_branch("main") | ||
|
||
mock_run_shell_command.assert_called_once_with(["git", "checkout", "main"]) | ||
|
||
|
||
async def test_checkout_remote_branch(mocker: MockerFixture): | ||
from src.plugins.github.handlers.git import GitHandler | ||
|
||
mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command") | ||
|
||
git_handler = GitHandler() | ||
git_handler.checkout_remote_branch("main") | ||
|
||
mock_run_shell_command.assert_any_call(["git", "fetch", "origin", "main"]) | ||
mock_run_shell_command.assert_any_call(["git", "checkout", "main"]) | ||
|
||
|
||
async def test_commit_and_push(mocker: MockerFixture): | ||
from src.plugins.github.handlers.git import GitHandler | ||
|
||
mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command") | ||
|
||
git_handler = GitHandler() | ||
git_handler.commit_and_push("commit message", "main", "author") | ||
|
||
mock_run_shell_command.assert_any_call( | ||
["git", "config", "--global", "user.name", "author"] | ||
) | ||
mock_run_shell_command.assert_any_call( | ||
["git", "config", "--global", "user.email", "[email protected]"] | ||
) | ||
mock_run_shell_command.assert_any_call(["git", "add", "-A"]) | ||
mock_run_shell_command.assert_any_call(["git", "commit", "-m", "commit message"]) | ||
mock_run_shell_command.assert_any_call(["git", "fetch", "origin"]) | ||
mock_run_shell_command.assert_any_call(["git", "diff", "origin/main", "main"]) | ||
mock_run_shell_command.assert_any_call(["git", "push", "origin", "main", "-f"]) | ||
|
||
|
||
async def test_delete_origin_branch(mocker: MockerFixture): | ||
from src.plugins.github.handlers.git import GitHandler | ||
|
||
mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command") | ||
|
||
git_handler = GitHandler() | ||
git_handler.delete_origin_branch("main") | ||
|
||
mock_run_shell_command.assert_called_once_with( | ||
["git", "push", "origin", "--delete", "main"] | ||
) | ||
|
||
|
||
async def test_switch_branch(mocker: MockerFixture): | ||
from src.plugins.github.handlers.git import GitHandler | ||
|
||
mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command") | ||
|
||
git_handler = GitHandler() | ||
git_handler.switch_branch("main") | ||
|
||
mock_run_shell_command.assert_called_once_with(["git", "switch", "-C", "main"]) |