Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test systemd services #256

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mybox/package/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ async def local_version(self) -> Optional[str]:

async def postinstall_linux(self):
if self.services:
await self.driver.with_root(True).run("systemctl", "daemon-reload")
driver = self.driver.with_root(True)
await driver.run("systemctl", "daemon-reload")
for service in self.services:
await self.driver.with_root(True).run("systemctl", "enable", service)
await driver.run("systemctl", "enable", "--now", service)

async def postinstall_macos(self):
pass
Expand Down
24 changes: 23 additions & 1 deletion tests/package/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from mybox.package import Package

from ..base import CI, DOCKER
from .base import PackageArgs, PackageTestBase


Expand Down Expand Up @@ -37,7 +38,7 @@ async def check_applicable(self) -> None:


class CaskFormulaPrecedence(PackageTestBase):
# affects_system = True
affects_system = True

async def check_applicable(self) -> None:
await super().check_applicable()
Expand Down Expand Up @@ -154,3 +155,24 @@ async def check_applicable(self) -> None:
await super().check_applicable()
if not (await self.driver.os()).switch(linux=True, macos=False):
pytest.skip("This test is only applicable on Linux.")


class TestService(PackageTestBase):
async def constructor_args(self) -> PackageArgs:
return {"system": "apache2", "service": "apache2"}

async def check_installed_command(self):
return ["ps", "aux"]

check_installed_output = "apache2"

async def check_applicable(self) -> None:
await super().check_applicable()
if not CI:
pytest.skip("Test affects local system.")
(await self.driver.os()).switch_(
linux=lambda _: None,
macos=lambda: pytest.skip("Service test is only applicable on Linux"),
)
if DOCKER:
pytest.skip("Daemon relies on systemd, which is not available in Docker.")