|
1 | 1 | # frozen_string_literal: true |
2 | 2 | require 'test_helper' |
| 3 | +require 'tempfile' |
| 4 | +require 'ostruct' |
| 5 | +require 'json' |
3 | 6 |
|
4 | 7 | module CI::Queue |
5 | 8 | class ConfigurationTest < Minitest::Test |
@@ -128,5 +131,66 @@ def test_report_timeout_set |
128 | 131 | assert_equal 45, config.report_timeout |
129 | 132 | end |
130 | 133 |
|
| 134 | + def test_load_known_flaky_tests_with_valid_file |
| 135 | + Tempfile.open('known_flaky_tests.json') do |file| |
| 136 | + test_data = [ |
| 137 | + { 'testSuite' => 'TestClass1', 'testName' => 'test_method1' }, |
| 138 | + { 'testSuite' => 'TestClass2', 'testName' => 'test_method2' } |
| 139 | + ] |
| 140 | + file.write(test_data.to_json) |
| 141 | + file.close |
| 142 | + |
| 143 | + known_flaky_tests = Configuration.load_known_flaky_tests(file.path) |
| 144 | + assert_includes known_flaky_tests, 'TestClass1#test_method1' |
| 145 | + assert_includes known_flaky_tests, 'TestClass2#test_method2' |
| 146 | + assert_equal 2, known_flaky_tests.size |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + def test_load_known_flaky_tests_with_missing_file |
| 151 | + known_flaky_tests = Configuration.load_known_flaky_tests('/tmp/does-not-exist.json') |
| 152 | + assert_empty known_flaky_tests |
| 153 | + |
| 154 | + known_flaky_tests = Configuration.load_known_flaky_tests(nil) |
| 155 | + assert_empty known_flaky_tests |
| 156 | + end |
| 157 | + |
| 158 | + def test_load_known_flaky_tests_with_invalid_json |
| 159 | + Tempfile.open('invalid.json') do |file| |
| 160 | + file.write('{ invalid json }') |
| 161 | + file.close |
| 162 | + |
| 163 | + known_flaky_tests = Configuration.load_known_flaky_tests(file.path) |
| 164 | + assert_empty known_flaky_tests |
| 165 | + end |
| 166 | + end |
| 167 | + |
| 168 | + def test_known_flaky_method |
| 169 | + known_flaky_tests = Set.new(['TestClass1#test_method1', 'TestClass2#test_method2']) |
| 170 | + config = Configuration.new(known_flaky_tests: known_flaky_tests) |
| 171 | + |
| 172 | + assert config.known_flaky?('TestClass1#test_method1') |
| 173 | + assert config.known_flaky?('TestClass2#test_method2') |
| 174 | + refute config.known_flaky?('TestClass3#test_method3') |
| 175 | + end |
| 176 | + |
| 177 | + def test_from_env_with_known_flaky_tests |
| 178 | + Tempfile.open('known_flaky_tests.json') do |file| |
| 179 | + test_data = [ |
| 180 | + { 'testSuite' => 'TestClass1', 'testName' => 'test_method1' }, |
| 181 | + { 'testSuite' => 'TestClass2', 'testName' => 'test_method2' } |
| 182 | + ] |
| 183 | + file.write(test_data.to_json) |
| 184 | + file.close |
| 185 | + |
| 186 | + env = { 'CI_QUEUE_KNOWN_FLAKY_TESTS' => file.path } |
| 187 | + config = Configuration.from_env(env) |
| 188 | + |
| 189 | + assert config.known_flaky?('TestClass1#test_method1') |
| 190 | + assert config.known_flaky?('TestClass2#test_method2') |
| 191 | + refute config.known_flaky?('TestClass3#test_method3') |
| 192 | + end |
| 193 | + end |
| 194 | + |
131 | 195 | end |
132 | 196 | end |
0 commit comments