@@ -125,15 +125,15 @@ def tid(self) -> str:
125
125
),
126
126
)
127
127
128
- def expand (self , template_dir : str , target_dir : str ) -> None :
128
+ def expand (self , template_dir : str , target_dir : str , namespace : str ) -> None :
129
129
"""Expand test case This will create the target folder, copy files and render render templates."""
130
130
logging .info ("Expanding test case id [%s]" , self .tid )
131
131
td_root = path .join (template_dir , self .name )
132
132
tc_root = path .join (target_dir , self .name , self .tid )
133
133
_mkdir_ignore_exists (tc_root )
134
134
test_env = Environment (loader = FileSystemLoader (path .join (template_dir , self .name )), trim_blocks = True )
135
135
test_env .globals ["lookup" ] = ansible_lookup
136
- test_env .globals ["NAMESPACE" ] = determine_namespace (self .tid )
136
+ test_env .globals ["NAMESPACE" ] = determine_namespace (self .tid , namespace )
137
137
sub_level : int = 0
138
138
for root , dirs , files in walk (td_root ):
139
139
sub_level += 1
@@ -315,7 +315,12 @@ class EffectiveTestSuite:
315
315
316
316
317
317
def expand (
318
- suite : str , effective_test_suites : List [EffectiveTestSuite ], template_dir : str , output_dir : str , kuttl_tests : str
318
+ suite : str ,
319
+ effective_test_suites : List [EffectiveTestSuite ],
320
+ template_dir : str ,
321
+ output_dir : str ,
322
+ kuttl_tests : str ,
323
+ namespace : str ,
319
324
) -> int :
320
325
"""Expand test suite."""
321
326
try :
@@ -324,14 +329,14 @@ def expand(
324
329
_mkdir_ignore_exists (output_dir )
325
330
_expand_kuttl_tests (ets .test_cases , output_dir , kuttl_tests )
326
331
for test_case in ets .test_cases :
327
- test_case .expand (template_dir , output_dir )
332
+ test_case .expand (template_dir , output_dir , namespace )
328
333
except StopIteration as exc :
329
334
raise ValueError (f"Cannot expand test suite [{ suite } ] because cannot find it in [{ kuttl_tests } ]" ) from exc
330
335
return 0
331
336
332
337
333
- def determine_namespace (testcase_name : str ) -> str :
334
- """Generate a namespace name for the given test case.
338
+ def determine_namespace (testcase_name : str , prefered_namespace : str ) -> str :
339
+ """Generate a namespace name for the given test case unless a prefered namespace name is given .
335
340
336
341
The format of the namespace name is "kuttl-<hash>" where hash is the first 10 chars of the test
337
342
case's sha256 value.
@@ -343,8 +348,11 @@ def determine_namespace(testcase_name: str) -> str:
343
348
different syntactic restrictions.
344
349
Therefore, to be on the safe side, the namespace name is kept as simple as possible.
345
350
"""
346
- hash = sha256 (testcase_name .encode ("utf-8" )).hexdigest ()
347
- return f"kuttl-{ hash [:10 ]} "
351
+ if prefered_namespace :
352
+ return prefered_namespace
353
+ else :
354
+ hash = sha256 (testcase_name .encode ("utf-8" )).hexdigest ()
355
+ return f"kuttl-{ hash [:10 ]} "
348
356
349
357
350
358
def _expand_kuttl_tests (test_cases , output_dir : str , kuttl_tests : str ) -> None :
0 commit comments