Skip to content

Commit 957073f

Browse files
authored
fix: long test ids lead to os error (#35)
* fix: shorten test ids > 255 chars * cleanup and changelog
1 parent 2bddac8 commit 957073f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
## Fixed
8+
9+
- Cap generated test ids to 255 characters to avoid file system errors ([#35]).
10+
11+
[#35]: https://github.com/stackabletech/beku.py/pull/35
12+
713
## 0.0.10 - 2024-11-06
814

915
## Added

src/beku/kuttl.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import os
77
import re
8+
import hashlib
89
from dataclasses import dataclass, field
910
from functools import cached_property
1011
from hashlib import sha256
@@ -94,6 +95,11 @@ def make_test_source_with_context(
9495
return TestFile(file_name=file_name, source_dir=source_dir, dest_dir=dest_dir)
9596

9697

98+
def tid_short_hash(tid: str) -> str:
99+
"""Take the first 10 chars of the hash of the given `tid`."""
100+
return hashlib.sha256(tid.encode()).hexdigest()[:10]
101+
102+
97103
@dataclass(frozen=True)
98104
class TestCase:
99105
"""A test case is an instance of test definition together with a set of Jinja variables used to render all
@@ -113,8 +119,11 @@ def tid(self) -> str:
113119
"""Return the test id. Used as destination folder name for the generated test case.
114120
The result is part of a full directory name of the test case. Therefore, the OS filesystem
115121
directory separator is replaced with underscore.
122+
123+
Since the result is also used as a folder name, we restrict it's length to 255 characters.
124+
This is because some filesystems complain if the name is longer that that.
116125
"""
117-
return re.sub(
126+
name = re.sub(
118127
f"[{os.sep}:]",
119128
"_",
120129
"_".join(
@@ -124,6 +133,12 @@ def tid(self) -> str:
124133
)
125134
),
126135
)
136+
max_len = 255
137+
if len(name) > max_len:
138+
name_hash = tid_short_hash(name)
139+
return f"{name[: max_len - len(name_hash) - 1]}_{name_hash}"
140+
else:
141+
return name
127142

128143
def expand(self, template_dir: str, target_dir: str, namespace: str) -> None:
129144
"""Expand test case This will create the target folder, copy files and render render templates."""

0 commit comments

Comments
 (0)