Skip to content

Commit

Permalink
add tests for setopt and tsflags
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Sep 11, 2024
1 parent 4e74ec9 commit 125beaf
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 35 deletions.
39 changes: 39 additions & 0 deletions pytests/repo/tdnf-test-doc.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# tdnf-test-doc spec file
#
Summary: basic install test file.
Name: tdnf-test-doc
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/usr/share/doc/tdnf-test-doc
echo "hello" > %_topdir/%buildroot/usr/share/doc/tdnf-test-doc/README
mkdir -p %_topdir/%buildroot/lib/systemd/system/
cat << EOF >> %_topdir/%buildroot/lib/systemd/system/tdnf-test-doc.service
[Unit]
Description=tdnf-test-doc.service for whatprovides test.
EOF

%files
%doc /usr/share/doc/tdnf-test-doc/README
/lib/systemd/system/tdnf-test-doc.service

%changelog
* Tue Nov 15 2016 Xiaolin Li <[email protected]> 1.0.1-2
- Add a service file for whatprovides test.
* Tue Dec 15 2015 Priyesh Padmavilasom <[email protected]> 1.0
- Initial build. First version
32 changes: 31 additions & 1 deletion pytests/tests/test_baseurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def setup_test(utils):

def teardown_test(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
if os.path.isdir(WORKDIR):
shutil.rmtree(WORKDIR)
filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME)
if os.path.isfile(filename):
os.remove(filename)
utils.erase_package(pkgname)


def test_multiple_baseurls(utils):
Expand All @@ -54,4 +54,34 @@ def test_multiple_baseurls(utils):
'--disablerepo=*', '--enablerepo={}'.format(reponame),
'install', pkgname],
cwd=workdir)
assert ret['retval'] == 0
assert utils.check_package(pkgname)


def test_multiple_baseurls_setopt(utils):
reponame = REPONAME
workdir = WORKDIR
utils.makedirs(workdir)

filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME)
# we should get a 404 for the first url and skip to the next one
baseurls = "http://localhost:8080/doesntexist"
utils.create_repoconf(filename, baseurls, reponame)

ret = utils.run(['tdnf',
'--disablerepo=*', '--enablerepo={}'.format(reponame),
f'--setopt={reponame}.baseurl=http://localhost:8080/photon-test',
'makecache'],
cwd=workdir)
assert ret['retval'] == 0

pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
ret = utils.run(['tdnf',
'-y', '--nogpgcheck',
'--disablerepo=*', '--enablerepo={}'.format(reponame),
f'--setopt={reponame}.baseurl=http://localhost:8080/photon-test',
'install', pkgname],
cwd=workdir)
assert ret['retval'] == 0
assert utils.check_package(pkgname)
34 changes: 0 additions & 34 deletions pytests/tests/test_noscripts.py

This file was deleted.

156 changes: 156 additions & 0 deletions pytests/tests/test_tsflags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#
# Copyright (C) 2019 - 2022 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (the "License");
# you may not use this file except in compliance with the License. The terms
# of the License are located in the COPYING file of this distribution.
#

import os
import subprocess
import pytest
import shutil


WORKDIR = '/root/test_tsflags'
TEST_CONF_FILE = 'tdnf.conf'
TEST_CONF_PATH = os.path.join(WORKDIR, TEST_CONF_FILE)


@pytest.fixture(scope='function', autouse=True)
def setup_test(utils):
yield
teardown_test(utils)


def teardown_test(utils):
packages = ["tdnf-bad-pre", utils.config["mulversion_pkgname"], "tdnf-test-doc"]
utils.run(['tdnf', 'erase', '-y'] + packages)

try:
os.remove(TEST_CONF_PATH)
except OSError:
pass


# Verify that the package is really bad:
def test_install_normal(utils):
pkgname = 'tdnf-bad-pre'
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname])
assert ret['retval'] == 1525


def test_install_noscripts(utils):
pkgname = 'tdnf-bad-pre'
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=noscripts', pkgname])
assert ret['retval'] == 0


def test_install_noscripts_nodocs(utils):
pkgname = 'tdnf-bad-pre'
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=noscripts', '--setopt=tsflags=nodocs', pkgname])
assert ret['retval'] == 0


def test_install_justdb(utils):
pkgname = utils.config["mulversion_pkgname"]
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=justdb', pkgname])
assert ret['retval'] == 0

# package should look like it's installed, but no files should be installed
assert utils.check_package(pkgname)
process = subprocess.run(['rpm', '-ql', pkgname], stdout=subprocess.PIPE, text=True)
for f in process.stdout.split():
assert not os.path.exists(f)


# opposite of --justdb
def test_install_nodb(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)

ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=nodb', pkgname])
assert ret['retval'] == 0

# package should appear to not be installed, but files should be there:
assert not utils.check_package(pkgname)
process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True)
for f in process.stdout.split():
if f.startswith("/"):
assert os.path.exists(f)


# opposite of --justdb
def test_install_nodocs(utils):
pkgname = "tdnf-test-doc"
utils.erase_package(pkgname)

ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=nodocs', pkgname])
assert ret['retval'] == 0

# make sure packe is installed
assert utils.check_package(pkgname)
# but no doc file
assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README")


def test_install_multiple(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)

ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'--setopt=tsflags=nodb nodocs', pkgname])
assert ret['retval'] == 0

# package should appear to not be installed, but files should be there:
assert not utils.check_package(pkgname)
process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True)
for f in process.stdout.split():
if f.startswith("/"):
assert os.path.exists(f)

# no doc file
assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README")


def test_install_multiple_from_config(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)

tdnf_conf = os.path.join(utils.config['repo_path'], 'tdnf.conf')

utils.makedirs(WORKDIR)
shutil.copy(tdnf_conf, TEST_CONF_PATH)
utils.edit_config({'tsflags': "nodb nodocs"}, section='main', filename=TEST_CONF_PATH)

ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'-c', TEST_CONF_PATH, pkgname])
assert ret['retval'] == 0

# package should appear to not be installed, but files should be there:
assert not utils.check_package(pkgname)
process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True)
for f in process.stdout.split():
if f.startswith("/"):
assert os.path.exists(f)

# no doc file
assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README")

# do this again, but override config settings to "normal":
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck',
'-c', TEST_CONF_PATH, '--setopt=tsflags=', pkgname])
assert ret['retval'] == 0

assert utils.check_package(pkgname)

# check all files exist - that includes doc files:
process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True)
for f in process.stdout.split():
if f.startswith("/"):
assert os.path.exists(f)

0 comments on commit 125beaf

Please sign in to comment.