diff --git a/t/16-utils-git.t b/t/16-utils-git.t new file mode 100644 index 000000000000..0a0b7e9fc28a --- /dev/null +++ b/t/16-utils-git.t @@ -0,0 +1,37 @@ +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +use Test::Most; +use Test::Warnings ':report_warnings'; +use Test::MockModule; +use Test::MockObject; +use FindBin; +use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib"; +use OpenQA::Test::TimeLimit '10'; +use OpenQA::Git; + +my $mock = Test::MockModule->new('OpenQA::Utils'); +$mock->mock('run_cmd_with_log_return_error', sub { + return { status => 0 } +}); + +my $mock_app = Test::MockObject->new(); +$mock_app->set_always('config', { + 'global' => { 'scm' => 'git' }, + 'scm git' => { 'do_push' => 'yes' } +}); + +my $mock_user = Test::MockObject->new(); +$mock_user->set_always('fullname', 'Test User'); +$mock_user->set_always('email', 'test.user@example.com'); + +my $git = OpenQA::Git->new(app => $mock_app, dir => './t', user => $mock_user); + +my $result = $git->commit({ + add => ['16-utils-git.t'], + message => 'Test commit message', +}); + +is $result, 'Unable to push Git commit', 'Commit method correctly handles push failure'; + +done_testing;