# encoding module ProxyTester module Cli class Test < Thor desc 'rspec', 'Run rspec tests' option :test_cases_directory, type: :string, desc: 'Directory with test cases' option :tags, type: :array, desc: 'Filter tests based on tags' def rspec ProxyTester.config = ProxyTester::Config.new(options[:config_file]) if options[:config_file] ProxyTester.config.log_level = options[:log_level] if options[:log_level] ProxyTester.config.debug_mode = options[:debug_mode] if options[:debug_mode] ProxyTester.config.test_cases_directory = options[:test_cases_directory] if options[:test_cases_directory] ProxyTester.config.lock ProxyTester.ui_logger.level = ProxyTester.config.log_level ProxyTester.enable_debug_mode if ProxyTester.config.debug_mode ProxyTester::RspecRunner.new(options[:tags]).run end desc 'url', 'Fetch url' option :count, type: :numeric, desc: 'Number of requests', default: 10 option :timeout, type: :numeric, desc: 'Wait n seconds before kill children', default: 60 option :proxy, type: :array, desc: 'System(s) under test', required: true option :user, type: :string, desc: 'User for authentication', default: ENV['USER'] option :log_level, type: :string, desc: 'Log level' option :concurrent, type: :boolean, desc: 'Simulate concurrent requests', default: false option :output, type: :string, desc: 'Write output to file' def url(*urls) ProxyTester.config = ProxyTester::Config.new(options[:config_file]) if options[:config_file] ProxyTester.config.log_level = options[:log_level] if options[:log_level] ProxyTester.config.debug_mode = options[:debug_mode] if options[:debug_mode] ProxyTester.config.lock ProxyTester.ui_logger.level = ProxyTester.config.log_level ProxyTester.enable_debug_mode if ProxyTester.config.debug_mode proxies = options[:proxy].collect { |p| HttpProxy.new(p) } unless options[:user].blank? user = User.new user.name = options[:user] while user.password.blank? user.password = HighLine.new.ask("Enter password for proxy user \"#{user.name}\": ") { |q| q.echo = '*' } end puts '' proxies.each { |p| p.use_user user } end output = options.fetch(:output, $stdout) if output.kind_of? String output = File.open(output, 'w') else output = $stdout end Actions::ClearEnvironment.new.run proxies.each do |p| ProxyTester.ui_logger.debug "Using proxy \"#{p.to_string}\"" ProxyTester.ui_logger.debug "Using user \"#{user.to_string}\"" action = Actions::FetchUrls.new( urls: urls, timeout: options[:timeout], count: options[:count], proxy: p, concurrent: options[:concurrent], output: output, ) action.run end end end end end