Merge pull request #265 from mhaskel/MODULES-1232
[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   if File.exists?(check_args_for_keyfile(args.extras))
47     ENV['BEAKER_keyfile'] = check_args_for_keyfile(args.extras)
48   end
49 end
50
51 def build_beaker_command(args)
52   cmd = ["beaker"]
53   cmd << "--type #{args[:type]}" unless !args[:type]
54   if File.exists?("./.beaker-#{args[:type]}.cfg")
55     cmd << "--options-file ./.beaker-#{args[:type]}.cfg"
56   end
57   if File.exists?(@hosts_config)
58     cmd << "--hosts #{@hosts_config}"
59   end
60   if File.exists?('./spec/acceptance/beaker_helper.rb')
61     cmd << "--pre-suite ./spec/acceptance/beaker_helper.rb"
62   end
63   if File.exists?("./spec/acceptance/beaker")
64     cmd << "--tests ./spec/acceptance/beaker"
65   end
66   if File.exists?(check_args_for_keyfile(args.extras))
67     cmd << "--keyfile #{check_args_for_keyfile(args.extras)}"
68   end
69   cmd.join(" ")
70 end
71
72 def check_args_for_keyfile(extra_args)
73   keyfile = ''
74   extra_args.each do |a|
75     keyfile = a unless (`ssh-keygen -l -f #{a}`.gsub(/\n/,"").match(/is not a .*key file/))
76   end
77   return keyfile
78 end