|
106 | 106 | describe '#fail_if_requested_check_never_run' do |
107 | 107 | it 'raises an exception if check_name is not empty and all_checks is' do |
108 | 108 | service.config.check_name = 'test' |
| 109 | + service.config.discovery_timeout = 0 |
109 | 110 |
|
110 | 111 | all_checks = [] |
111 | 112 | allow(service).to receive(:query_check_status).and_return all_checks |
|
149 | 150 | it 'raises an exception when check_regexp is set and no checks match' do |
150 | 151 | service.config.check_regexp = 'non-matching-regexp' |
151 | 152 | service.config.fail_on_no_checks = true |
| 153 | + service.config.discovery_timeout = 0 |
152 | 154 |
|
153 | 155 | all_checks = [] |
154 | 156 | allow(service).to receive(:query_check_status).and_return all_checks |
|
160 | 162 | it 'raises an exception when check_name is set and no checks match' do |
161 | 163 | service.config.check_name = 'non-existing-check' |
162 | 164 | service.config.fail_on_no_checks = true |
| 165 | + service.config.discovery_timeout = 0 |
163 | 166 |
|
164 | 167 | all_checks = [] |
165 | 168 | allow(service).to receive(:query_check_status).and_return all_checks |
|
170 | 173 | end |
171 | 174 | end |
172 | 175 |
|
| 176 | + describe '#wait_for_check_discovery' do |
| 177 | + before do |
| 178 | + service.config.ref = '_' |
| 179 | + service.config.client.access_token = '_' |
| 180 | + end |
| 181 | + |
| 182 | + it 'polls until checks are found within the timeout' do |
| 183 | + service.config.check_name = 'delayed-check' |
| 184 | + service.config.fail_on_no_checks = true |
| 185 | + service.config.discovery_timeout = 30 |
| 186 | + service.wait = 0 |
| 187 | + |
| 188 | + completed_check = [Helpers::CheckRun.new(name: 'delayed-check', status: 'completed', conclusion: 'success')] |
| 189 | + call_count = 0 |
| 190 | + allow(service).to receive(:query_check_status) do |
| 191 | + call_count += 1 |
| 192 | + call_count < 3 ? [] : completed_check |
| 193 | + end |
| 194 | + |
| 195 | + output = with_captured_stdout { service.call } |
| 196 | + expect(output).to include('Matching checks have not been found yet') |
| 197 | + end |
| 198 | + |
| 199 | + it 'logs discovery message when fail_on_no_checks is false' do |
| 200 | + service.config.check_name = 'non-existing-check' |
| 201 | + service.config.fail_on_no_checks = false |
| 202 | + service.config.discovery_timeout = 30 |
| 203 | + |
| 204 | + allow(service).to receive(:query_check_status).and_return [] |
| 205 | + |
| 206 | + output = with_captured_stdout { service.call } |
| 207 | + expect(output).not_to include('Matching checks have not been found yet') |
| 208 | + end |
| 209 | + |
| 210 | + it 'succeeds immediately when fail_on_no_checks is false' do |
| 211 | + service.config.check_name = 'non-existing-check' |
| 212 | + service.config.fail_on_no_checks = false |
| 213 | + service.config.discovery_timeout = 30 |
| 214 | + |
| 215 | + allow(service).to receive(:query_check_status).and_return [] |
| 216 | + |
| 217 | + output = with_captured_stdout { service.call } |
| 218 | + expect(output).to include('No checks found matching the filter, but fail-on-no-checks is false') |
| 219 | + end |
| 220 | + |
| 221 | + it 'fails after discovery timeout is exceeded' do |
| 222 | + service.config.check_name = 'never-found-check' |
| 223 | + service.config.fail_on_no_checks = true |
| 224 | + service.config.discovery_timeout = 0 |
| 225 | + service.wait = 0 |
| 226 | + |
| 227 | + allow(service).to receive(:query_check_status).and_return [] |
| 228 | + |
| 229 | + expected_msg = 'The requested check was never run against this ref, exiting...' |
| 230 | + expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 231 | + end |
| 232 | + end |
| 233 | + |
173 | 234 | describe '#fail_unless_all_conclusions_allowed' do |
174 | 235 | it 'raises an exception if some check conclusion is not allowed' do |
175 | 236 | all_checks = [ |
|
0 commit comments