Class: VagrantPlugins::GPIICi::Command::CITest

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-gpii-ci/command/test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



6
7
8
# File 'lib/vagrant-gpii-ci/command/test.rb', line 6

def self.synopsis
  "Run tests on a machine"
end

Instance Method Details

#executeObject



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
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-gpii-ci/command/test.rb', line 10

def execute
  param_options = {}
  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant ci test [options] [name|id]"
    o.on("--stage STAGE", String, "Execute specific stage") do |s|
      param_options[:stage] = s
    end
  end
  argv = parse_options(opts)
  return if !argv

  @env.ui.info("Launching tests...")

  ci_tests = @env.instance_variable_get(:@ci_tests)

  with_target_vms(argv, single_target: true) do |machine|
    if machine.config.vm.communicator == :winrm
      cwd = "cd c:\\vagrant"
    else
      cwd = "cd /vagrant"
    end
    ci_tests["#{machine.config.vm.hostname}"].each do | provisioner, stages |

      if provisioner.eql?("shell")
        stages.each do |stagename, stagescripts|
          next if (param_options.include?(:stage) and not stagename.eql?(param_options[:stage]))
          stagescripts.each do | script |

            options = {}
            options[:color] = :blue
            @env.ui.info("Running shell script:")
            @env.ui.info("#{script}",options)

            machine.communicate.execute("#{cwd}; #{script}") do |type, data|
              handle_comm(type, data, machine)
            end

          end
        end
      end
    end 
  end
end

#handle_comm(type, data, machine) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vagrant-gpii-ci/command/test.rb', line 54

def handle_comm(type, data, machine)
  if [:stdout,:stderr].include?(type)
    # Output the data with the proper color based on the stream.
    color = type == :stdout ? :green : :red
  
    # Clear out the newline since we add one
    data = data.chomp

    return if data.empty?
  
    options = {}
    options[:color] = color 

    machine.ui.info(data, options)
  end
end