-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netbsd add unit-test for case pkgin is present
- Loading branch information
Showing
1 changed file
with
14 additions
and
18 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 |
---|---|---|
@@ -1,25 +1,21 @@ | ||
import os.path | ||
|
||
import cloudinit.distros.netbsd | ||
|
||
import unittest.mock as mock | ||
|
||
real_path_exists = os.path.exists | ||
def _pkgin_exists_factory(expectation): | ||
def _mock_exists(path): | ||
if path.endswith("/pkgin"): | ||
return expectation | ||
return real_path_exists(path) | ||
return _mock_exists | ||
|
||
def test_init_and_pkgin(monkeypatch): | ||
@mock.patch("cloudinit.distros.netbsd.os") | ||
def test_init_with_pkgin(m_os): | ||
m_os.path.exists.return_value = True | ||
cfg = {} | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(os.path, "exists", _pkgin_exists_factory(True)) | ||
distro = cloudinit.distros.netbsd.NetBSD("netbsd", cfg, None) | ||
assert distro.pkg_cmd_upgrade_prefix == ['pkgin', '-y', 'full-upgrade'] | ||
distro = cloudinit.distros.netbsd.NetBSD("netbsd", cfg, None) | ||
assert distro.pkg_cmd_upgrade_prefix == ['pkgin', '-y', 'full-upgrade'] | ||
|
||
|
||
@mock.patch("cloudinit.distros.netbsd.os") | ||
def test_init_without_pkgin(m_os): | ||
m_os.path.exists.return_value = False | ||
cfg = {} | ||
|
||
m.setattr(os.path, "exists", _pkgin_exists_factory(False)) | ||
distro = cloudinit.distros.netbsd.NetBSD("netbsd", cfg, None) | ||
print(distro.pkg_cmd_upgrade_prefix) | ||
assert distro.pkg_cmd_upgrade_prefix == None | ||
distro = cloudinit.distros.netbsd.NetBSD("netbsd", cfg, None) | ||
assert distro.pkg_cmd_upgrade_prefix is None |