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)


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

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.to_s,
      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.



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

def config
  @config
end

#machinesHash<String, OsVm::Machine> (readonly)

Returns:

  • (Hash<String, OsVm::Machine>)


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

def machines
  @machines
end

#optsObject (readonly, protected)

Returns the value of attribute opts.



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

def opts
  @opts
end

#testObject (readonly, protected)

Returns the value of attribute test.



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

def test
  @test
end

Instance Method Details

#breakpointObject

Invoke interactive shell from within a test



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

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

#do_runObject (protected)



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/test-runner/test_evaluator.rb', line 73

def do_run
  yield

  machines.each_value do |m|
    m.stop if m.running?
  end
ensure
  machines.each_value do |m|
    m.kill
    m.destroy if opts[:destructive]
    m.finalize
    m.cleanup
  end
end

#interactiveObject

Run interactive shell



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

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

#runObject

Run the test script



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

def run
  do_run do
    test_script
  end
end

#start_allObject

Start all machines



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

def start_all
  machines.each(&:start)
end

#test_scriptObject (protected)



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

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