Module: VirtualMonkey::TestCaseInterface

Included in:
DeploymentRunner
Defined in:
lib/virtualmonkey/test_case_interface.rb

Instance Method Summary collapse

Instance Method Details

#behavior(sym, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/virtualmonkey/test_case_interface.rb', line 7

def behavior(sym, *args)
  begin
    rerun_test
    #pre-command
    populate_settings unless @populated
    #command
    result = __send__(sym, *args)
    #post-command
    continue_test
  rescue Exception => e
    dev_mode?(e)
  end while @rerun_last_command.pop
  result
end

#probe(server, command, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/virtualmonkey/test_case_interface.rb', line 48

def probe(server, command, &block)
  # run command on servers matching "server" over ssh
  result = ""
  @servers.select { |s| s.nickname =~ /#{server}/ }.each { |s|
    begin
      rerun_test
      result_temp = s.spot_check_command(command)
      if not yield(result_temp[:output])
        raise "FATAL: Server #{s.nickname} failed probe. Got #{result_temp[:output]}"
      end
      continue_test
    rescue Exception => e
      dev_mode?(e)
    end while @rerun_last_command.pop
    result += result_temp[:output]
  }
end

#set_var(sym, *args) ⇒ Object



3
4
5
# File 'lib/virtualmonkey/test_case_interface.rb', line 3

def set_var(sym, *args)
  behavior(sym, *args)
end

#verify(method, expectation, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/virtualmonkey/test_case_interface.rb', line 22

def verify(method, expectation, *args)
  if expectation =~ /((exception)|(error)|(fatal)|(fail))/i
    expect = "fail"
    error_msg = expectation.split(":")[1..-1].join(":")
  elsif expectation =~ /((success)|(succeed)|(pass))/i
    expect = "pass"
  elsif expectation =~ /nil/i
    expect = "nil"
  else
    raise 'Syntax Error: verify expects a "pass", "fail", or "nil"'
  end

  begin
    rerun_test
    result = __send__(command, *args)
    if expect != "pass" and not (result == nil and expect == "nil")
      raise "FATAL: Failed verification"
    end
    continue_test
  rescue Exception => e
    if not ("#{e}" =~ /#{error_msg}/ and expect == "fail")
      dev_mode?(e)
    end
  end while @rerun_last_command.pop
end