Merge pull request #1988 from dbungert/test-apt-mountpoint-install-tree
apt: fix mountpoint-install-tree test write dir
This commit is contained in:
commit
e3b0805d3c
|
@ -108,39 +108,40 @@ class TestAptConfigurer(SubiTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def test_run_apt_config_check(self):
|
async def test_run_apt_config_check(self):
|
||||||
self.configurer.configured_tree = OverlayMountpoint(
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
upperdir="upperdir-install-tree",
|
self.configurer.configured_tree = OverlayMountpoint(
|
||||||
lowers=["lowers1-install-tree"],
|
upperdir="upperdir-install-tree",
|
||||||
mountpoint="mountpoint-install-tree",
|
lowers=["lowers1-install-tree"],
|
||||||
)
|
mountpoint=pathlib.Path(tempdir) / "mountpoint-install-tree",
|
||||||
|
|
||||||
async def astart_success(cmd, **kwargs):
|
|
||||||
"""Simulates apt-get update behaving normally."""
|
|
||||||
proc = await astart_command(
|
|
||||||
["sh", "-c", "cat"], **kwargs, stdin=subprocess.PIPE
|
|
||||||
)
|
)
|
||||||
proc.stdin.write(APT_UPDATE_SUCCESS.encode("utf-8"))
|
|
||||||
proc.stdin.write_eof()
|
|
||||||
return proc
|
|
||||||
|
|
||||||
async def astart_failure(cmd, **kwargs):
|
async def astart_success(cmd, **kwargs):
|
||||||
"""Simulates apt-get update failing."""
|
"""Simulates apt-get update behaving normally."""
|
||||||
proc = await astart_command(
|
proc = await astart_command(
|
||||||
["sh", "-c", "cat; exit 1"], **kwargs, stdin=subprocess.PIPE
|
["sh", "-c", "cat"], **kwargs, stdin=subprocess.PIPE
|
||||||
)
|
)
|
||||||
proc.stdin.write(APT_UPDATE_FAILURE.encode("utf-8"))
|
proc.stdin.write(APT_UPDATE_SUCCESS.encode("utf-8"))
|
||||||
proc.stdin.write_eof()
|
proc.stdin.write_eof()
|
||||||
return proc
|
return proc
|
||||||
|
|
||||||
output = io.StringIO()
|
async def astart_failure(cmd, **kwargs):
|
||||||
with patch(self.astart_sym, side_effect=astart_success):
|
"""Simulates apt-get update failing."""
|
||||||
await self.configurer.run_apt_config_check(output)
|
proc = await astart_command(
|
||||||
self.assertEqual(output.getvalue(), APT_UPDATE_SUCCESS)
|
["sh", "-c", "cat; exit 1"], **kwargs, stdin=subprocess.PIPE
|
||||||
|
)
|
||||||
|
proc.stdin.write(APT_UPDATE_FAILURE.encode("utf-8"))
|
||||||
|
proc.stdin.write_eof()
|
||||||
|
return proc
|
||||||
|
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
with patch(self.astart_sym, side_effect=astart_failure):
|
with patch(self.astart_sym, side_effect=astart_success):
|
||||||
with self.assertRaises(AptConfigCheckError):
|
|
||||||
await self.configurer.run_apt_config_check(output)
|
await self.configurer.run_apt_config_check(output)
|
||||||
|
self.assertEqual(output.getvalue(), APT_UPDATE_SUCCESS)
|
||||||
|
|
||||||
|
output = io.StringIO()
|
||||||
|
with patch(self.astart_sym, side_effect=astart_failure):
|
||||||
|
with self.assertRaises(AptConfigCheckError):
|
||||||
|
await self.configurer.run_apt_config_check(output)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
|
Loading…
Reference in New Issue