Skip to content

Commit 92b422e

Browse files
committed
fix: shorten test ids > 255 chars
1 parent 2bddac8 commit 92b422e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/beku/kuttl.py

Lines changed: 11 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,10 @@ 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+
return hashlib.sha256(tid.encode()).hexdigest()[:10]
100+
101+
97102
@dataclass(frozen=True)
98103
class TestCase:
99104
"""A test case is an instance of test definition together with a set of Jinja variables used to render all
@@ -114,7 +119,7 @@ def tid(self) -> str:
114119
The result is part of a full directory name of the test case. Therefore, the OS filesystem
115120
directory separator is replaced with underscore.
116121
"""
117-
return re.sub(
122+
name = re.sub(
118123
f"[{os.sep}:]",
119124
"_",
120125
"_".join(
@@ -124,6 +129,11 @@ def tid(self) -> str:
124129
)
125130
),
126131
)
132+
if len(name) > 255:
133+
hash = tid_short_hash(name)
134+
return f"{name[:244]}_{hash}"
135+
else:
136+
return name
127137

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

0 commit comments

Comments
 (0)