Skip to content

Commit 9c16a9c

Browse files
Merge pull request #141 from bheuvel/feature/testing_rake_rspec
Improve testing with rake (and rspec)
2 parents b4ec378 + 0050cb5 commit 9c16a9c

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

Rakefile

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ require 'rubygems'
22
require 'bundler/setup'
33
require 'rspec/core/rake_task'
44

5+
RSpec::Core::RakeTask.new(:functionaltest) do |t|
6+
t.pattern = "*_spec.rb"
7+
t.rspec_opts = "-fd"
8+
end
9+
510
# Immediately sync all stdout so that tools like buildbot can
611
# immediately load in the output.
712
$stdout.sync = true
@@ -22,6 +27,13 @@ task :default => "spec"
2227

2328

2429
namespace :functional_tests do
30+
31+
# Name must match folder beneath functional-tests/
32+
functional_test_names = [
33+
'vmlifecycle',
34+
'rsync'
35+
]
36+
2537
desc "Check for required enviroment variables for functional testing"
2638
task :check_environment do
2739
[
@@ -49,42 +61,24 @@ namespace :functional_tests do
4961

5062
desc "Run all functional tests"
5163
task :all => [ :check_environment ] do
52-
Rake::Task['functional_tests:vmlifecycle'].invoke
53-
Rake::Task['functional_tests:rsync'].invoke
54-
end
55-
56-
desc "Run functional test: VM Life cycle"
57-
task :vmlifecycle => [ :check_environment ] do
58-
Dir.chdir(File.expand_path("../", __FILE__))
59-
test_dir_name='vmlifecycle'
60-
Dir.chdir("functional-tests/#{test_dir_name}/")
61-
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
62-
puts ""
63-
puts "Testing #{test_dir_name}"
64-
puts ""
65-
ENV['TEST_NAME'] = "vagrant_cloudstack_functional_test-#{test_dir_name}"
66-
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
67-
sh %{ vagrant up }
68-
sh %{ vagrant destroy -f }
64+
functional_test_names.each do |test_name|
65+
Rake::Task["functional_tests:#{test_name}"].invoke
6966
end
70-
Dir.chdir(File.expand_path("../", __FILE__))
7167
end
7268

73-
desc "Run functional test: RSync"
74-
task :rsync => [ :check_environment ] do
75-
Dir.chdir(File.expand_path("../", __FILE__))
76-
test_dir_name='rsync'
77-
Dir.chdir("functional-tests/#{test_dir_name}/")
78-
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
79-
puts ""
80-
puts "Testing #{test_dir_name}"
81-
puts ""
82-
ENV['TEST_NAME'] = "vagrant_cloudstack_functional_test-#{test_dir_name}"
83-
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
84-
sh %{ vagrant up }
85-
sh %{ vagrant ssh -c "ls /vagrant; echo;" }
86-
sh %{ vagrant destroy -f }
69+
70+
functional_test_names.each do |test_dir_name|
71+
desc "Run functional test: #{test_dir_name}"
72+
task test_dir_name => [ :check_environment ] do
73+
Dir.chdir("#{File.expand_path('../', __FILE__)}/functional-tests/#{test_dir_name}/")
74+
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
75+
76+
ENV['TEST_NAME'] = "vagrant_cloudstack_functional_test-#{test_dir_name}"
77+
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
78+
puts "Running RSpec tests in folder : #{test_dir_name}"
79+
puts "Using Vagrant file : #{ENV['VAGRANT_VAGRANTFILE']}"
80+
Rake::Task[:functionaltest].execute
81+
end
8782
end
88-
Dir.chdir(File.expand_path("../", __FILE__))
8983
end
9084
end

functional-tests/rsync/Vagrantfile.advanced_networking

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Vagrant.require_version '>= 1.5.0'
99
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1010
config.vm.box = ENV['LINUX_TEMPLATE_NAME']
1111

12+
config.vm.synced_folder ".", "/vagrant", type: "rsync",
13+
rsync__exclude: [".git/", "vendor"]
14+
1215
config.vm.provider :cloudstack do |cloudstack, override|
1316
cloudstack.display_name = ENV['TEST_NAME']
1417

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe 'VM RSync' do
2+
it 'does rsync to the VM' do
3+
expect(`vagrant up`).to include('Machine is booted and ready for use!')
4+
expect($?.exitstatus).to eq(0)
5+
expect(`vagrant ssh -c "ls /vagrant; echo;"`).to include('Vagrantfile.advanced_networking')
6+
expect(`vagrant destroy --force`).to include('Terminating the instance...')
7+
expect($?.exitstatus).to eq(0)
8+
end
9+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe 'VM Life Cycle' do
2+
it 'starts Linux and Windows VM' do
3+
expect(`vagrant up`).to include(
4+
'linux-box: Machine is booted and ready for use!',
5+
'windows-box: Machine is booted and ready for use!'
6+
)
7+
expect($?.exitstatus).to eq(0)
8+
end
9+
it 'destroys Linux and Windows VM' do
10+
expect(`vagrant destroy --force`).to include('Terminating the instance...')
11+
expect($?.exitstatus).to eq(0)
12+
end
13+
end

0 commit comments

Comments
 (0)