lib/sippy_cup/runner.rb in sippy_cup-0.1.1 vs lib/sippy_cup/runner.rb in sippy_cup-0.2.0
- old
+ new
@@ -1,16 +1,33 @@
require 'yaml'
+require 'active_support/core_ext/hash'
module SippyCup
class Runner
def initialize(opts = {})
- @options = opts
+ @options = ActiveSupport::HashWithIndifferentAccess.new opts
end
+ def compile
+ raise ArgumentError, "Must provide scenario steps" unless @options[:steps]
+ scenario = SippyCup::Scenario.new @options[:name].titleize, source: @options[:source], destination: @options[:destination]
+ @options[:steps].each do |step|
+ instruction, arg = step.split ' ', 2
+ if arg && !arg.empty?
+ # Strip leading/trailing quotes if present
+ arg.gsub!(/^'|^"|'$|"$/, '')
+ scenario.send instruction.to_sym, arg
+ else
+ scenario.send instruction
+ end
+ end
+ scenario.compile!
+ end
+
def prepare_command
[:scenario, :source, :destination, :max_concurrent, :calls_per_second, :number_of_calls].each do |arg|
- raise "Must provide #{arg}!" unless @options[arg]
+ raise ArgumentError, "Must provide #{arg}!" unless @options[arg]
end
command = "sudo sipp"
source_port = @options[:source_port] || '8836'
sip_user = @options[:sip_user] || '1'
command << " -i #{@options[:source]} -p #{source_port} -sf #{File.expand_path @options[:scenario]}"
@@ -32,6 +49,6 @@
p "Test completed successfully!"
p "Statistics logged at #{File.expand_path @options[:stats_file]}" if @options[:stats_file]
end
end
-end
\ No newline at end of file
+end