-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add a simple unit test for the NVMe module
- Loading branch information
1 parent
4957d84
commit c807e23
Showing
2 changed files
with
39 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
|
||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
from blivet.nvme import nvme | ||
|
||
|
||
class NVMeModuleTestCase(unittest.TestCase): | ||
|
||
host_nqn = "nqn.2014-08.org.nvmexpress:uuid:01234567-8900-abcd-efff-abcdabcdabcd" | ||
|
||
@patch("blivet.nvme.os") | ||
@patch("blivet.nvme.blockdev") | ||
def test_nvme_module(self, bd, os): | ||
self.assertIsNotNone(nvme) | ||
bd.nvme_get_host_nqn.return_value = self.host_nqn | ||
bd.nvme_get_host_id.return_value = None # None = generate from host_nqn | ||
os.path.isdir.return_value = False | ||
|
||
# startup | ||
with patch.object(nvme, "write") as write: | ||
nvme.startup() | ||
write.assert_called_once_with("/", overwrite=False) | ||
|
||
self.assertTrue(nvme.started) | ||
self.assertEqual(nvme._hostnqn, self.host_nqn) | ||
self.assertEqual(nvme._hostid, "01234567-8900-abcd-efff-abcdabcdabcd") | ||
|
||
# write | ||
with patch("blivet.nvme.open") as op: | ||
nvme.write("/test") | ||
|
||
os.makedirs.assert_called_with("/test/etc/nvme/", 0o755) | ||
op.assert_any_call("/test/etc/nvme/hostnqn", "w") | ||
op.assert_any_call("/test/etc/nvme/hostid", "w") |