# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The # ASF licenses this file to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance with the # License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require 'rake' require 'rake/testtask' require 'rubygems/package_task' require 'rspec/core/rake_task' begin require 'ci/reporter/rake/test_unit' rescue LoadError end $top_srcdir = File.dirname(__FILE__) $:.unshift File.join($top_srcdir, 'lib') begin require 'cucumber' require 'cucumber/rake/task' namespace :cucumber do %w(mock ec2 sbc).each do |driver| namespace driver do Cucumber::Rake::Task.new(:test) do |t| t.cucumber_opts = "../tests/#{driver} --format pretty" t.rcov = false end Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = "../tests/#{driver} --format html --out ../tests/tmp/cucumber_#{driver}.html" t.rcov = false end Cucumber::Rake::Task.new(:junit) do |t| t.cucumber_opts = "../tests/#{driver} --format junit --out #{File.join(File.dirname(__FILE__), "tmp", "junit_#{driver}")}" end end end end Cucumber::Rake::Task.new(:cimi) do |t| t.cucumber_opts = "tests/cimi/features/*.feature --format pretty" t.rcov = false end namespace :cimi do Cucumber::Rake::Task.new(:machines) do |t| t.cucumber_opts = "tests/cimi/features/machines.feature --format pretty" t.rcov = false end Cucumber::Rake::Task.new(:machine_images) do |t| t.cucumber_opts = "tests/cimi/features/machine_images.feature --format pretty" t.rcov = false end Cucumber::Rake::Task.new(:volumes) do |t| t.cucumber_opts = "tests/cimi/features/volumes.feature --format pretty" t.rcov = false end end rescue LoadError end namespace :test do %w(mock rackspace rhevm openstack google).each do |driver| desc "Run #{driver} unit tests" Rake::TestTask.new(driver) { |t| t.test_files = ['tests/common.rb', "tests/drivers/#{driver}/setup.rb"] + FileList.new("tests/drivers/#{driver}/*_test.rb") + FileList.new('tests/rabbit_test.rb') t.options = "-v -v" t.verbose = true t.warning = false } end desc "Run CIMI frontend tests" Rake::TestTask.new "cimi" do |t| t.test_files = ["tests/cimi/cimi.rb", "tests/cimi/common/*_test.rb"] t.options = "-v -v" t.verbose = true t.warning = false end end desc "Call our Test::Unit suite" task :test do %w(mock rackspace rhevm openstack google).each do |driver| Rake::Task["test:#{driver}"].reenable Rake::Task["test:#{driver}"].invoke end end desc "Call our Cucumber suite" task :cucumber do %w(mock ec2 sbc).each do |driver| Rake::Task["cucumber:#{driver}:test"].reenable Rake::Task["cucumber:#{driver}:test"].invoke end end RSpec::Core::RakeTask.new do |t| t.pattern = FileList['spec/**/*_spec.rb'] t.rspec_opts = [ "--format", "nested", "--color", "-r ./spec/spec_helper.rb"] end Dir['spec/**/*_spec.rb'].each do |file| RSpec::Core::RakeTask.new("spec:#{File.basename(file).gsub(/_spec\.rb$/, '')}") do |t| t.pattern = FileList[file] t.rspec_opts = [ "--format", "nested", "--color", "-r ./spec/spec_helper.rb"] end end begin require 'yard' YARD::Rake::YardocTask.new do |t| t.files = ['lib/**/*.rb', '*.rb'] # optional end rescue LoadError end spec = Gem::Specification.load('deltacloud-core.gemspec') Gem::PackageTask.new(spec) do |pkg| pkg.need_tar = true end namespace :routes do desc "List all REST routes for the Deltacloud API" task :api do require 'deltacloud/server.rb' Sinatra::Rabbit::routes.each do |m, path| puts sprintf("\033[1;30m%-8s\033[0m %s", m.to_s.upcase, path) end end desc "List all REST routes for the CIMI API" task :cimi do require 'cimi/server.rb' Sinatra::Rabbit::routes.each do |m, path| puts sprintf("\033[1;30m%-8s\033[0m %s", m.to_s.upcase, path) end end end namespace :mock do namespace :fixtures do desc "Setup Mock driver fixtures" task 'setup' do if ENV["DELTACLOUD_MOCK_STORAGE"] storage_root = ENV["DELTACLOUD_MOCK_STORAGE"] elsif ENV["USER"] storage_root = File::join("/var/tmp", "deltacloud-mock-#{ENV["USER"]}") else raise "Please set either the DELTACLOUD_MOCK_STORAGE or USER environment variable" end data = Dir::glob(File::join(File::dirname(__FILE__), "lib", "deltacloud", "drivers", "mock", "data", "*")) FileUtils::mkdir_p(storage_root, :verbose => true) FileUtils::cp_r(data, storage_root, :verbose => true) end desc "Remove Mock driver fixtures" task 'clean' do if ENV["DELTACLOUD_MOCK_STORAGE"] storage_root = ENV["DELTACLOUD_MOCK_STORAGE"] elsif ENV["USER"] storage_root = File::join("/var/tmp", "deltacloud-mock-#{ENV["USER"]}") else raise "Please set either the DELTACLOUD_MOCK_STORAGE or USER environment variable" end FileUtils::rm_rf(storage_root, :verbose => true) end desc "Reset Mock driver fixtures" task 'reset' do Rake::Task["mock:fixtures:clean"].reenable Rake::Task["mock:fixtures:clean"].invoke Rake::Task["mock:fixtures:setup"].reenable Rake::Task["mock:fixtures:setup"].invoke end end end