Merge pull request #77 from branan/updated_module_layout
Update the module to the new layout for easier testing and packaging
This commit is contained in:
commit
ece11c57fa
7 changed files with 82 additions and 38 deletions
3
.fixtures.yml
Normal file
3
.fixtures.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fixtures:
|
||||||
|
symlinks:
|
||||||
|
"mysql": "#{source_dir}"
|
|
@ -3,8 +3,6 @@ source :rubygems
|
||||||
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
|
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
|
||||||
|
|
||||||
gem 'puppet', puppetversion
|
gem 'puppet', puppetversion
|
||||||
gem 'hiera', '>= 0.3.0'
|
|
||||||
gem 'hiera-puppet', '>= 0.3.0'
|
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rake', '>= 0.9.0'
|
gem 'rake', '>= 0.9.0'
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*.swp
|
*.swp
|
||||||
|
pkg/
|
||||||
|
|
|
@ -4,7 +4,7 @@ rvm:
|
||||||
before_script:
|
before_script:
|
||||||
- "[ '2.6.9' = $PUPPET_VERSION ] && git clone git://github.com/puppetlabs/puppetlabs-create_resources.git spec/fixtures/modules/create_resources || true"
|
- "[ '2.6.9' = $PUPPET_VERSION ] && git clone git://github.com/puppetlabs/puppetlabs-create_resources.git spec/fixtures/modules/create_resources || true"
|
||||||
after_script:
|
after_script:
|
||||||
script: "rake spec"
|
script: "rake spec_full"
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
@ -14,3 +14,4 @@ env:
|
||||||
- PUPPET_VERSION=2.6.9
|
- PUPPET_VERSION=2.6.9
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
gemfile: .gemfile
|
||||||
|
|
94
Rakefile
94
Rakefile
|
@ -1,44 +1,84 @@
|
||||||
require 'rubygems'
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'rspec/core/rake_task'
|
require 'rspec/core/rake_task'
|
||||||
require 'fileutils'
|
require 'yaml'
|
||||||
|
|
||||||
task :default do
|
task :default => [:spec]
|
||||||
system("rake -T")
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Run all rspec-puppet tests"
|
desc "Run all module spec tests (Requires rspec-puppet gem)"
|
||||||
RSpec::Core::RakeTask.new(:spec) do |t|
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||||
t.rspec_opts = ['--color']
|
t.rspec_opts = ['--color']
|
||||||
# ignores fixtures directory.
|
|
||||||
t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
|
t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_module_version
|
# This is a helper for the self-symlink entry of fixtures.yml
|
||||||
gitdesc = %x{git describe}.chomp
|
def source_dir
|
||||||
semver = gitdesc.gsub(/v?(\d+\.\d+\.\d+)-?(.*)/) do
|
File.dirname(__FILE__)
|
||||||
newver = "#{$1}"
|
|
||||||
newver << "git-#{$2}" unless $2.empty?
|
|
||||||
newver
|
|
||||||
end
|
|
||||||
modulefile = File.read("Modulefile")
|
|
||||||
modulefile.gsub!(/^\s*version\s+'.*?'/, "version '#{semver}'")
|
|
||||||
File.open("Modulefile", 'w') do |f|
|
|
||||||
f.write(modulefile)
|
|
||||||
end
|
|
||||||
semver
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Build Puppet Module Package"
|
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
|
task :build do
|
||||||
system("gimli README*.markdown")
|
# This will be deprecated once puppet-module is a face.
|
||||||
FileUtils.cp "Modulefile", "Modulefile.bak"
|
begin
|
||||||
update_module_version
|
Gem::Specification.find_by_name('puppet-module')
|
||||||
system("puppet-module build")
|
rescue Gem::LoadError, NoMethodError
|
||||||
FileUtils.mv "Modulefile.bak", "Modulefile"
|
require 'puppet/face'
|
||||||
|
pmod = Puppet::Face['module', :current]
|
||||||
|
pmod.build('./')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Clean the package directory"
|
desc "Clean a built module package"
|
||||||
task :clean do
|
task :clean do
|
||||||
FileUtils.rm_rf("pkg/")
|
FileUtils.rm_rf("pkg/")
|
||||||
end
|
end
|
||||||
|
|
1
spec/fixtures/modules/mysql
vendored
1
spec/fixtures/modules/mysql
vendored
|
@ -1 +0,0 @@
|
||||||
../../../
|
|
|
@ -1,16 +1,18 @@
|
||||||
|
require 'rubygems'
|
||||||
require 'puppet'
|
require 'puppet'
|
||||||
require 'rspec'
|
|
||||||
require 'rspec-puppet'
|
require 'rspec-puppet'
|
||||||
|
|
||||||
def param_value(subject, type, title, param)
|
def param_value(subject, type, title, param)
|
||||||
subject.resource(type, title).send(:parameters)[param.to_sym]
|
subject.resource(type, title).send(:parameters)[param.to_sym]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Puppet.parse_config
|
||||||
|
puppet_module_path = Puppet[:modulepath]
|
||||||
|
|
||||||
|
fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
||||||
|
|
||||||
RSpec.configure do |c|
|
RSpec.configure do |c|
|
||||||
c.module_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/modules'))
|
fixture_module_path = File.join(fixture_path, 'modules')
|
||||||
# Using an empty site.pp file to avoid: https://github.com/rodjek/rspec-puppet/issues/15
|
c.module_path = [fixture_module_path, puppet_module_path].join(":")
|
||||||
c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
|
c.manifest_dir = File.join(fixture_path, 'manifests')
|
||||||
# Use fixtures for config file mainly to support using our own hiera.yaml settings.
|
|
||||||
# Pending: https://github.com/rodjek/rspec-puppet/pull/21
|
|
||||||
# c.config = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/puppet.conf'))
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue