Class: TestRunner::TestEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/test-runner/test_evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test, **opts) ⇒ TestEvaluator

Returns a new instance of TestEvaluator.

Parameters:

  • test (Test)
  • opts (Hash)

Options Hash (**opts):

  • :default_timeout (Integer)
  • :destructive (Boolean)
  • :state_dir (String)
  • :sock_dir (String)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/test-runner/test_evaluator.rb', line 14

def initialize(test, **opts)
  @test = test
  @config = TestConfig.build(test)
  @opts = opts
  @machines = {}

  config[:machines].each do |name, cfg|
    var = :"@#{name}"
    m = OsVm::Machine.new(
      name,
      OsVm::MachineConfig.new(cfg),
      opts[:state_dir],
      opts[:sock_dir],
      default_timeout: opts[:default_timeout],
      hash_base: test.path
    )
    instance_variable_set(var, m)

    define_singleton_method(name) do
      instance_variable_get(var)
    end

    machines[name] = m
  end
end

Instance Attribute Details

#configObject (readonly, protected)

Returns the value of attribute config.



66
67
68
# File 'lib/test-runner/test_evaluator.rb', line 66

def config
  @config
end

#machinesObject (readonly)

Returns the value of attribute machines.



6
7
8
# File 'lib/test-runner/test_evaluator.rb', line 6

def machines
  @machines
end

#optsObject (readonly, protected)

Returns the value of attribute opts.



66
67
68
# File 'lib/test-runner/test_evaluator.rb', line 66

def opts
  @opts
end

#testObject (readonly, protected)

Returns the value of attribute test.



66
67
68
# File 'lib/test-runner/test_evaluator.rb', line 66

def test
  @test
end

Instance Method Details

#breakpointObject

Invoke interactive shell from within a test



60
61
62
# File 'lib/test-runner/test_evaluator.rb', line 60

def breakpoint
  binding.pry # rubocop:disable Lint/Debugger
end

#do_runObject (protected)



72
73
74
75
76
77
78
79
80
81
# File 'lib/test-runner/test_evaluator.rb', line 72

def do_run
  yield
ensure
  machines.each_value do |m|
    m.kill
    m.destroy if opts[:destructive]
    m.finalize
    m.cleanup
  end
end

#interactiveObject

Run interactive shell



48
49
50
51
52
# File 'lib/test-runner/test_evaluator.rb', line 48

def interactive
  do_run do
    binding.pry # rubocop:disable Lint/Debugger
  end
end

#runObject

Run the test script



41
42
43
44
45
# File 'lib/test-runner/test_evaluator.rb', line 41

def run
  do_run do
    test_script
  end
end

#start_allObject

Start all machines



55
56
57
# File 'lib/test-runner/test_evaluator.rb', line 55

def start_all
  machines.each(&:start)
end

#test_scriptObject (protected)



68
69
70
# File 'lib/test-runner/test_evaluator.rb', line 68

def test_script
  binding.eval(config[:testScript]) # rubocop:disable Security/Eval
end