@@ -8,25 +8,24 @@ class Validator
8
8
def initialize
9
9
@test_suite_id = ENV [ 'TEST_SUITE_ID' ]
10
10
@test_suites = ENV [ 'TEST_SUITES' ]
11
+ @use_test_suite_id_cache = ENV [ 'USE_TEST_SUITE_ID_CACHE' ]
11
12
12
13
if @test_suite_id . nil? ^ @test_suites . nil?
13
14
raise (
14
15
ValidationError ,
15
- 'Both the enviornment variables TEST_SUITE_ID and TEST_SUITES are not set'
16
+ 'Both the environment variables TEST_SUITE_ID and TEST_SUITES are not set'
16
17
)
17
18
end
18
19
19
20
setup
20
21
end
21
22
22
23
def valid? ( ref , cache_files )
23
- last_run_regex = Regexp . new ( format ( @last_run_files_regex , ref : ref ) )
24
-
25
- return false if cache_files . count { |file | file . match? ( last_run_regex ) } != @last_run_files_count
26
-
27
- cache_regex = Regexp . new ( format ( @cached_files_regex , ref : ref ) )
28
-
29
- cache_files . count { |file | file . match? ( cache_regex ) } == @cached_files_count
24
+ if @use_test_suite_id_cache
25
+ test_suite_id_specific_validation ( ref , cache_files )
26
+ else
27
+ general_validation ( ref , cache_files )
28
+ end
30
29
end
31
30
32
31
private
@@ -36,7 +35,7 @@ def setup
36
35
@last_run_files_count = 1
37
36
@last_run_files_regex = '/%<ref>s/last_run.json$'
38
37
@cached_files_count = CACHE_FILES_PER_TEST_SUITE
39
- @cached_files_regex = '/%<ref>s/[0-9a-f]{32}/.+.json'
38
+ @cached_files_regex = '/%<ref>s/[0-9a-f]{32}/.+.json$ '
40
39
else
41
40
@test_suites = @test_suites . to_i
42
41
@test_suites_regex = ( 1 ..@test_suites ) . to_a . join ( '|' )
@@ -47,6 +46,29 @@ def setup
47
46
@cached_files_regex = "/%<ref>s/(#{ @test_suites_regex } )/[0-9a-f]{32}/.+.json$"
48
47
end
49
48
end
49
+
50
+ def general_validation ( ref , cache_files )
51
+ last_run_regex = Regexp . new ( format ( @last_run_files_regex , ref : ref ) )
52
+
53
+ return false if cache_files . count { |file | file . match? ( last_run_regex ) } != @last_run_files_count
54
+
55
+ cache_regex = Regexp . new ( format ( @cached_files_regex , ref : ref ) )
56
+
57
+ cache_files . count { |file | file . match? ( cache_regex ) } == @cached_files_count
58
+ end
59
+
60
+ def test_suite_id_specific_validation ( ref , cache_files )
61
+ # Here, we ensure that the regex is dynamically adjusted for the specific test suite
62
+ # Adjusting for specific test_suite_id in the regex patterns
63
+ last_run_regex = Regexp . new ( "/#{ ref } /#{ @test_suite_id } /last_run.json$" )
64
+ cache_regex = Regexp . new ( "/#{ ref } /#{ @test_suite_id } /[0-9a-f]{32}/.+.json$" )
65
+
66
+ # Validate presence of the last run file for the specific test suite
67
+ return false unless cache_files . any? { |file | file . match? ( last_run_regex ) }
68
+
69
+ # Check if any cache files for the specific test suite are present
70
+ cache_files . any? { |file | file . match? ( cache_regex ) }
71
+ end
50
72
end
51
73
end
52
74
end
0 commit comments