diff options
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/mock_agent.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/support/mock_agent.rb b/test/support/mock_agent.rb index b86de4f..9c21345 100644 --- a/test/support/mock_agent.rb +++ b/test/support/mock_agent.rb @@ -13,6 +13,52 @@ when 'reverse_input' when 'basename' file_path = ARGV.fetch(0) print File.basename(file_path) +when 'join_args' + print ARGV.join('|') +when 'count_pass_through' + counter_path = ARGV.fetch(0) + count = File.file?(counter_path) ? File.read(counter_path).to_i : 0 + File.write(counter_path, count + 1) + print stdin +when 'count_upcase' + counter_path = ARGV.fetch(0) + count = File.file?(counter_path) ? File.read(counter_path).to_i : 0 + File.write(counter_path, count + 1) + print stdin.upcase +when 'fail_then_pass' + counter_path = ARGV.fetch(0) + failures_before_success = Integer(ARGV.fetch(1, '1')) + message = ARGV.fetch(2, 'boom') + exit_code = Integer(ARGV.fetch(3, '7')) + count = File.file?(counter_path) ? File.read(counter_path).to_i : 0 + count += 1 + File.write(counter_path, count) + if count <= failures_before_success + warn message + exit exit_code + end + print stdin +when 'stream_chunks' + stderr_text = ARGV.pop.sub('--stderr=', '') if ARGV.last&.start_with?('--stderr=') + ARGV.each do |chunk| + $stdout.write(chunk) + $stdout.flush + sleep 0.01 + end + if stderr_text + $stderr.write(stderr_text) + $stderr.flush + end +when 'count_or_fail' + counter_path = ARGV.fetch(0) + marker_path = ARGV.fetch(1) + if File.exist?(marker_path) + warn ARGV.fetch(2, 'boom') + exit Integer(ARGV.fetch(3, '7')) + end + count = File.file?(counter_path) ? File.read(counter_path).to_i : 0 + File.write(counter_path, count + 1) + print stdin when 'pass_through' print stdin when 'upcase' |
