Skip to content

Commit

Permalink
tests(slurm_ops): add additional mocking for JWTKeyManager
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
NucciTheBoss committed Oct 6, 2024
1 parent 0619bbf commit 55e2ba5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/unit/test_slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"""Test slurm_ops library."""

import base64
import grp
import os
import pwd
import subprocess
import textwrap
from pathlib import Path
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 55e2ba5

Please sign in to comment.