From 994422f7ac59b9215ec9332732e0505170237110 Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Sun, 6 Oct 2024 12:16:15 -0400 Subject: [PATCH] tests(slurm_ops): add additional mocking for JWTKeyManager pyfakefs seemingly doesn't work for JWTKeyManager, so we need to manually mock the user and group for `shutil`. Just sets the user and group to the current user and group running the unit tests. Signed-off-by: Jason C. Nucciarone --- tests/unit/test_slurm_ops.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/test_slurm_ops.py b/tests/unit/test_slurm_ops.py index fdee8fd..cce467f 100644 --- a/tests/unit/test_slurm_ops.py +++ b/tests/unit/test_slurm_ops.py @@ -5,6 +5,9 @@ """Test slurm_ops library.""" import base64 +import grp +import os +import pwd import subprocess import textwrap from pathlib import Path @@ -162,9 +165,13 @@ def setUp(self): self.setUpPyfakefs() self.fs.create_file("/var/snap/slurm/common/.env") self.fs.create_file("/var/snap/slurm/common/var/lib/slurm/slurm.state/jwt_hs256.key") + + # pyfakefs inconsistently mocks JWTKeyManager so manually mock instead. self.manager.jwt._keyfile = Path( "/var/snap/slurm/common/var/lib/slurm/slurm.state/jwt_hs256.key" ) + self.manager.jwt._user = pwd.getpwuid(os.getuid()).pw_name + self.manager.jwt._group = grp.getgrgid(os.getgid()).gr_name self.manager.jwt._keyfile.write_text(JWT_KEY) def test_config_name(self, *_) -> None: