Skip to content

Commit

Permalink
add test for scriptlet redirection for json
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Jul 11, 2023
1 parent 68d2d62 commit 806ef20
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pytests/repo/tdnf-verbose-scripts.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# tdnf test spec file
#
Summary: basic install test file.
Name: tdnf-verbose-scripts
Version: 1.0.1
Release: 2
Vendor: VMware, Inc.
Distribution: Photon
License: VMware
Url: http://www.vmware.com
Group: Applications/tdnftest

%description
Part of tdnf test spec. Basic install/remove/upgrade test

%prep

%build

%install
mkdir -p %_topdir/%buildroot/lib/systemd/system/
echo %_topdir/%buildroot/lib/systemd/system/%{name}.service
cat << EOF >> %_topdir/%buildroot/lib/systemd/system/%{name}.service
[Unit]
Description=%{name}.service for rpm script test.
EOF

%post
echo "echo from post"
echo "echo to stderr from post" >&2

%postun
echo "echo from postun"
echo "echo to stderr from postun" >&2

%pre
echo "echo from pre"
echo "echo to stderr from pre" >&2

%preun
echo "echo from preun"
echo "echo to stderr from preun" >&2

%files
/lib/systemd/system/%{name}.service

%changelog
* Tue Jul 11 2023 Oliver Kurth <[email protected]>
- test script output redirection
40 changes: 40 additions & 0 deletions pytests/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import os


PKGNAME_VERBOSE_SCRIPTS = "tdnf-verbose-scripts"


@pytest.fixture(scope='function', autouse=True)
def setup_test(utils):
tdnfj = os.path.join(utils.config['bin_dir'], 'tdnfj')
Expand Down Expand Up @@ -98,6 +101,43 @@ def test_erase(utils):
assert pkg_found


# verbose rpm scriplets should not interfer with json output
def test_install_verbose(utils):
pkgname = PKGNAME_VERBOSE_SCRIPTS
utils.erase_package(pkgname)
ret = utils.run(['tdnf',
'-j', '-y', '--nogpgcheck',
'install', pkgname])
assert utils.check_package(pkgname)
install_info = json.loads("\n".join(ret['stdout']))

pkg_found = False
install_pkgs = install_info["Install"]
for p in install_pkgs:
if p['Name'] == pkgname:
pkg_found = True
break
assert pkg_found


def test_erase_verbose(utils):
pkgname = PKGNAME_VERBOSE_SCRIPTS
utils.install_package(pkgname)
ret = utils.run(['tdnf',
'-j', '-y', '--nogpgcheck',
'erase', pkgname])
assert not utils.check_package(pkgname)
install_info = json.loads("\n".join(ret['stdout']))

pkg_found = False
install_pkgs = install_info["Remove"]
for p in install_pkgs:
if p['Name'] == pkgname:
pkg_found = True
break
assert pkg_found


def test_check_update(utils):
ret = utils.run(['tdnf', '-j', 'check-update'])
d = json.loads("\n".join(ret['stdout']))
Expand Down

0 comments on commit 806ef20

Please sign in to comment.