summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 36a79986571363795c7e5aee93b7dce4202af719 (plain)
1
2
3
4
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'puppetlabs_spec_helper/rake_tasks'
require 'rake'

desc "Run beaker-rspec and beaker tests"
task 'beaker:test:all',[:host,:type] => ["rake:beaker:rspec:test", "rake:beaker:test"] do |t,args|
end

desc "Run beaker-rspec tests"
task 'beaker:rspec:test',[:host,:type] => [:set_beaker_variables] do |t,args|
  Rake::Task['beaker-rspec:test'].invoke(args)
end

desc "Run beaker tests"
task 'beaker:test',[:host,:type] => [:set_beaker_variables] do |t,args|
  sh(build_beaker_command args)
end

desc "Run beaker rspec tasks against pe"
RSpec::Core::RakeTask.new('beaker-rspec:test',[:host,:type]=>:set_beaker_variables) do |t,args|
  t.pattern     = 'spec/acceptance'
  t.rspec_opts  = '--color'
  t.verbose     = true
end

desc "Run beaker and beaker-rspec tasks"
task 'beaker:test:pe',:host do |t,args|
  args.with_defaults(:type=> 'pe')
  Rake::Task['beaker:test'].invoke(args[:host],args[:type])
end

task 'beaker:test:git',:host do |t,args|
  args.with_defaults({:type=> 'git'})
  Rake::Task['beaker:test'].invoke(args[:host],args[:type])
end

task :set_beaker_variables do |t,args|
  puts 'Setting environment variables for testing'
  if args[:host]
    ENV['BEAKER_set'] = args[:host]
    puts "Host to test #{ENV['BEAKER_set']}"
  end
  ENV['BEAKER_IS_PE'] = args[:type] == 'pe'? "true": "false"
  if ENV['BEAKER_setfile']
    @hosts_config = ENV['BEAKER_setfile']
  end
end

def build_beaker_command(args)
  cmd = ["beaker"]
  cmd << "--type #{args[:type]}" unless !args[:type]
  if File.exists?("./.beaker-#{args[:type]}.cfg")
    cmd << "--options-file ./.beaker-#{args[:type]}.cfg"
  end
  if File.exists?(@hosts_config)
    cmd << "--hosts #{@hosts_config}"
  end
  if File.exists?('./spec/acceptance/beaker_helper.rb')
    cmd << "--pre-suite ./spec/acceptance/beaker_helper.rb"
  end
  if File.exists?("./spec/acceptance/beaker")
    cmd << "--tests ./spec/acceptance/beaker"
  end
  cmd.join(" ")
end