File tree 2 files changed +11
-15
lines changed
2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -58,19 +58,16 @@ def test_held_package(host):
58
58
assert python .is_installed
59
59
assert python .version .startswith ("3.11." )
60
60
61
- @pytest .mark .destructive
62
61
@pytest .mark .testinfra_hosts ("docker://rockylinux9" )
63
- def test_rpm_package_broken_db (host ):
64
- with host .sudo ():
65
- # Corrupt RPM database so that we make RpmPackage.is_installed throw an exception
66
- host .run_test ('rpm --rebuilddb' )
67
- host .run_test ('dd if=/dev/zero of=$(rpm --dbpath)/Packages bs=1024 count=1024 seek=1024' )
62
+ def test_rpm_package_not_installed (host ):
63
+ # Pass an invalid value as package name, it returns exit code 1
64
+ pkg_name = "-3"
68
65
with pytest .raises (RuntimeError ) as excinfo :
69
- host .package ("zsh" ).is_installed
66
+ host .package (pkg_name ).is_installed
70
67
assert (
71
- "DB_PAGE_NOT_FOUND "
72
- in str ( excinfo . value )
73
- )
68
+ f"Could not check if RPM package ' { pkg_name } ' is installed. "
69
+ f"rpm: { pkg_name } : unknown option"
70
+ ) in str ( excinfo . value )
74
71
75
72
@pytest .mark .testinfra_hosts ("docker://rockylinux9" )
76
73
def test_non_default_package_tool (host ):
Original file line number Diff line number Diff line change @@ -165,14 +165,13 @@ def version(self):
165
165
class RpmPackage (Package ):
166
166
@property
167
167
def is_installed (self ):
168
- result = self .run ("rpm -q %s " , self .name )
168
+ result = self .run ("rpm -q --quiet %s 2>&1 " , self .name )
169
169
if result .succeeded :
170
170
return True
171
-
172
- if "not installed" in result .stdout or not result .stdout .startswith (self .name ):
171
+ elif result .failed and result .stdout == '' :
173
172
return False
174
-
175
- raise RuntimeError (f"Could not check if RPM package '{ self .name } ' is installed. { result } " )
173
+ else :
174
+ raise RuntimeError (f"Could not check if RPM package '{ self .name } ' is installed. { result . stdout } " )
176
175
177
176
@property
178
177
def version (self ):
You can’t perform that action at this time.
0 commit comments