-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP extending test coverage of OpenQA::Git
- Loading branch information
1 parent
0d86920
commit c81d797
Showing
1 changed file
with
44 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,44 @@ | ||
# 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->redefine('run_cmd_with_log_return_error', sub { | ||
my ($cmd) = @_; | ||
|
||
if ($cmd->[1] eq 'push') { | ||
# Simulate a failure when attempting to push | ||
return { status => 0 }; | ||
} | ||
# Simulate success for other git commands ('add', 'commit') | ||
return { status => 1 }; | ||
}); | ||
|
||
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', '[email protected]'); | ||
|
||
my $git = OpenQA::Git->new(app => $mock_app, dir => '.', user => $mock_user); | ||
|
||
my $result = $git->commit({ | ||
add => ['t/16-utils-git.t'], | ||
message => 'Test commit message', | ||
}); | ||
|
||
is $result, 'Unable to push Git commit', 'Commit method correctly handles push failure'; | ||
|
||
done_testing; |