Adjust Rake tasks for beaker testing
[puppet_vcsrepo.git] / Rakefile
1 require 'puppetlabs_spec_helper/rake_tasks'
2 require 'rake'
3
4 desc "Run beaker-rspec and beaker tests"
5 task 'beaker:test:all',[:host,:type] => ["rake:beaker:rspec:test", "rake:beaker:test"] do |t,args|
6 end
7
8 desc "Run beaker-rspec tests"
9 task 'beaker:rspec:test',[:host,:type] => [:set_beaker_variables] do |t,args|
10   Rake::Task['beaker-rspec:test'].invoke(args)
11 end
12
13 desc "Run beaker tests"
14 task 'beaker:test',[:host,:type] => [:set_beaker_variables] do |t,args|
15   sh(build_beaker_command args)
16 end
17
18 desc "Run beaker rspec tasks against pe"
19 RSpec::Core::RakeTask.new('beaker-rspec:test',[:host,:type]=>:set_beaker_variables) do |t,args|
20   t.pattern     = 'spec/acceptance'
21   t.rspec_opts  = '--color'
22   t.verbose     = true
23 end
24
25 desc "Run beaker and beaker-rspec tasks"
26 task 'beaker:test:pe',:host do |t,args|
27   args.with_defaults(:type=> 'pe')
28   Rake::Task['beaker:test'].invoke(args[:host],args[:type])
29 end
30
31 task 'beaker:test:git',:host do |t,args|
32   args.with_defaults({:type=> 'git'})
33   Rake::Task['beaker:test'].invoke(args[:host],args[:type])
34 end
35
36 task :set_beaker_variables do |t,args|
37   puts 'Setting environment variables for testing'
38   if args[:host]
39     ENV['BEAKER_set'] = args[:host]
40     puts "Host to test #{ENV['BEAKER_set']}"
41   end
42   ENV['BEAKER_IS_PE'] = args[:type] == 'pe'? "true": "false"
43   if ENV['BEAKER_setfile']
44     @hosts_config = ENV['BEAKER_setfile']
45   end
46 end
47
48 def build_beaker_command(args)
49   cmd = ["beaker"]
50   cmd << "--type #{args[:type]}" unless !args[:type]
51   if File.exists?("./.beaker-#{args[:type]}.cfg")
52     cmd << "--options-file ./.beaker-#{args[:type]}.cfg"
53   end
54   if File.exists?(@hosts_config)
55     cmd << "--hosts #{@hosts_config}"
56   end
57   if File.exists?('./spec/acceptance/beaker_helper.rb')
58     cmd << "--pre-suite ./spec/acceptance/beaker_helper.rb"
59   end
60   if File.exists?("./spec/acceptance/beaker")
61     cmd << "--tests ./spec/acceptance/beaker"
62   end
63   cmd.join(" ")
64 end