Skip to content

Commit

Permalink
netbsd add unit-test for case pkgin is present
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed Apr 19, 2020
1 parent d81426e commit 545095d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions tests/unittests/test_distros/test_netbsd.py
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

0 comments on commit 545095d

Please sign in to comment.