Class: VagrantTest::Command

Inherits:
Vagrant::Command::Base
  • Object
show all
Defined in:
lib/vagrant-test/command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
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
39
40
41
# File 'lib/vagrant-test/command.rb', line 5

def execute
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant test [vm-name]"
  end

  argv = parse_options(opts)
  return if !argv

  with_target_vms(argv[0]) do |vm|
    vm.env.action_runner.run(Vagrant::Action::General::Validate, {:vm=>vm, :ui=>vm.ui})

    if !vm.created? || vm.state != :running
      vm.ui.error("VM not running. Not running tests.")
    elsif (vm.config.test.internal_tests + vm.config.test.external_tests).empty?
      vm.ui.error("No tests defined.")
    else

      unless vm.config.test.internal_tests.empty?
        internal_tests = vm.config.test.internal_tests.map { |obj|
          File.join(V_ROOT, vm.config.test.dir, obj)
        }
        vm.ui.info("Running internal test(s): #{internal_tests.join(", ")}")
        vm.channel.sudo("#{vm.config.test.command} #{internal_tests.join(" ")}") do |type,data|
          print data if type == :stdout
        end
      end

      unless vm.config.test.external_tests.empty?
        external_tests = vm.config.test.external_tests.map { |obj|
          File.join(vm.config.test.dir, obj)
        }
        vm.ui.info("Running external test(s): #{external_tests.join(", ")}")
        system("#{vm.config.test.command} #{external_tests.join(" ")}")
      end
    end
  end
end