Add files for CI support

These changes make it easier for both humans and computers to run the spec tests

* Add `rake spec_full` and friends, which automatically checkout dependency modules
  prior to running spec tests
* Prepend fixtures modulepath instead of overriding
* Add a Travis-CI configuration file to enable easy CI
This commit is contained in:
Branan Purvine-Riley 2012-05-29 09:50:13 -07:00
parent ea532aa278
commit 0b0bf5adcd
5 changed files with 128 additions and 7 deletions

10
.fixtures.yml Normal file
View File

@ -0,0 +1,10 @@
fixtures:
repositories:
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"concat": "git://github.com/ripienaar/puppet-concat.git"
"keystone": "git://github.com/puppetlabs/puppetlabs-keystone.git"
"mysql": "git://github.com/puppetlabs/puppetlabs-mysql.git"
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
"rabbitmq": "git://github.com/puppetlabs/puppetlabs-rabbitmq.git"
symlinks:
"glance": "#{source_dir}"

12
.gemfile Normal file
View File

@ -0,0 +1,12 @@
source :rubygems
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
gem 'puppet', puppetversion
group :test do
gem 'rake', '>= 0.9.0'
gem 'rspec', '>= 2.8.0'
gem 'rspec-puppet', '>= 0.1.1'
gem 'mocha', '>= 0.11.0'
end

16
.travis.yml Normal file
View File

@ -0,0 +1,16 @@
language: ruby
rvm:
- 1.8.7
before_script:
after_script:
script: "rake spec_full"
branches:
only:
- master
env:
- PUPPET_VERSION=2.7.13
- PUPPET_VERSION=2.7.6
- PUPPET_VERSION=2.6.9
notifications:
email: false
gemfile: .gemfile

View File

@ -1,14 +1,91 @@
require 'rake'
require 'rspec/core/rake_task'
require 'yaml'
task :default => [:spec]
desc "Run all module spec tests (Requires rspec-puppet gem)"
task :spec do
system("rspec spec/**/*_spec.rb")
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--color']
t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
end
desc "Build package"
# This is a helper for the self-symlink entry of fixtures.yml
def source_dir
File.dirname(__FILE__)
end
def fixtures(category)
begin
fixtures = YAML.load_file(".fixtures.yml")["fixtures"]
rescue Errno::ENOENT
return {}
end
if not fixtures
abort("malformed fixtures.yml")
end
result = {}
if fixtures.include? category
fixtures[category].each do |fixture, source|
target = "spec/fixtures/modules/#{fixture}"
real_source = eval('"'+source+'"')
result[real_source] = target
end
end
return result
end
desc "Create the fixtures directory"
task :spec_prep do
fixtures("repositories").each do |repo, target|
File::exists?(target) || system("git clone #{repo} #{target}")
end
FileUtils::mkdir_p("spec/fixtures/modules")
fixtures("symlinks").each do |source, target|
File::exists?(target) || FileUtils::ln_s(source, target)
end
end
desc "Clean up the fixtures directory"
task :spec_clean do
fixtures("repositories").each do |repo, target|
FileUtils::rm_rf(target)
end
fixtures("symlinks").each do |source, target|
FileUtils::rm(target)
end
end
task :spec_full do
Rake::Task[:spec_prep].invoke
Rake::Task[:spec].invoke
Rake::Task[:spec_clean].invoke
end
desc "Build puppet module package"
task :build do
system("puppet-module build")
# This will be deprecated once puppet-module is a face.
begin
Gem::Specification.find_by_name('puppet-module')
rescue Gem::LoadError, NoMethodError
require 'puppet/face'
pmod = Puppet::Face['module', :current]
pmod.build('./')
end
end
desc "Clean a built module package"
task :clean do
FileUtils.rm_rf("pkg/")
end
desc "Check puppet manifests with puppet-lint"
task :lint do
# This requires pull request: https://github.com/rodjek/puppet-lint/pull/81
system("puppet-lint manifests")
system("puppet-lint tests")
end

View File

@ -1,5 +1,5 @@
require 'puppet'
require 'rubygems'
require 'puppet'
require 'rspec-puppet'
def param_value(subject, type, title, param)
@ -11,7 +11,13 @@ def verify_contents(subject, title, expected_lines)
(content.split("\n") & expected_lines).should == expected_lines
end
Puppet.parse_config
puppet_module_path = Puppet[:modulepath]
fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
RSpec.configure do |c|
c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
c.module_path = File.join(File.dirname(__FILE__), '../../')
fixture_module_path = File.join(fixture_path, 'modules')
c.module_path = [fixture_module_path, puppet_module_path].join(":")
c.manifest_dir = File.join(fixture_path, 'manifests')
end