Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
rfan1 committed Mar 22, 2024
1 parent 1cfed02 commit 72fb52f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions data/libgit2/pygit2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pygit2

url = "https://github.com/libgit2/libgit2"
path = "./libgit2_clone"

try:
pygit2.clone_repository(url, path)
print("Repository cloned successfully to {}".format(path))
except Exception as e:
print("Error: {}".format(e))
5 changes: 5 additions & 0 deletions lib/python_version_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ returns an array of strings with all the available python versions in the reposi
=cut

sub get_available_python_versions() {
my $get_latest_version = shift // '';
my @python3_versions = split(/\n/, script_output(qq[zypper se '/^python3[0-9]{1,2}\$/' | awk -F '|' '/python3[0-9]/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq]));
record_info("Available versions", "All available new python3 versions are: @python3_versions");
if ($get_latest_version) {
record_info("The latest version is: $python3_versions[$#python3_versions]");
return $python3_versions[$#python3_versions];
}
return @python3_versions;
}

Expand Down
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ schedule:
- console/coredump_collect
- console/valgrind
- console/sssd_389ds_functional
- console/libgit2
- console/zypper_log_packages
63 changes: 63 additions & 0 deletions tests/console/libgit2.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# SUSE's openQA tests
#
# Copyright 2024 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: Basic libgit2 test via python pygit2
# - Test should test on sle15sp6+ and tw, see https://jira.suse.com/browse/PED-7228
# - Package 'pygit2' requires Python '>=3.7'
# - Run some basic test (test_libgit2.py)
#
# Maintainer: QE Core <qe-core@suse.com>

use base "consoletest";
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use version_utils 'is_sle';
use utils "zypper_call";
use python_version_utils;
use registration 'add_suseconnect_product';

my $python3_version;
my $python_sub_version;

sub run {
select_serial_terminal;

# Install libgit2
if (is_sle) {
add_suseconnect_product("sle-module-desktop-applications");
add_suseconnect_product('sle-module-development-tools');
}
my $pkg_ver = script_output("zypper se '/^libgit2-[0-9].*[0-9]\$/' | awk -F '|' '/libgit2-[0-9]/ {gsub(\" \", \"\"); print \$2}' | uniq");
zypper_call "in $pkg_ver libgit2-tools";

# Install the latest python3 package
$python3_version = get_available_python_versions('1');
zypper_call "in $python3_version";
$python_sub_version = substr($python3_version, 7);

# Install pygit2
assert_script_run "pip3.$python_sub_version install pygit2";
# Run test script
assert_script_run "wget --quiet " . data_url('libgit2/pygit2_test.py') . " -O pygit2_test.py";
assert_script_run "python3.$python_sub_version pygit2_test.py";

# Cleanup
cleanup();
}

sub clean_up {
assert_script_run "pip3.$python_sub_version uninstall pygit2";
zypper_call "rm $python3_version";
assert_script_run "rm -rf libgit2";
}

sub post_fail_hook {
select_console 'log-console';
cleanup();
}

1;

0 comments on commit 72fb52f

Please sign in to comment.