diff options
-rw-r--r-- | .fixtures.yml | 3 | ||||
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | .gitlab-ci.yml | 48 | ||||
-rw-r--r-- | Gemfile | 22 | ||||
-rw-r--r-- | Rakefile | 19 | ||||
-rw-r--r-- | spec/classes/module_dir_spec.rb | 17 | ||||
-rw-r--r-- | spec/spec_helper.rb | 22 |
7 files changed, 128 insertions, 13 deletions
diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..58545a5 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,3 @@ +fixtures: + symlinks: + "common": "#{source_dir}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad8ff1f --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/pkg/ +/Gemfile.lock +/vendor/ +/spec/fixtures +/log +/.vagrant/ +/.bundle/ +/coverage/ +/.idea/ +*.iml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..79108a0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,48 @@ +image: leapcode/ruby +before_script: + - "[ -d /var/cache/gitlab-runner ] || sudo mkdir /var/cache/gitlab-runner" + - sudo chown cirunner:cirunner -R /var/cache/gitlab-runner + - bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}" + +.job_template: &job_definition + script: + # don't fail on lint warnings + - bundle exec rake lint || /bin/true + - bundle exec rake syntax + - bundle exec rake validate + - bundle exec rake spec + +# Default debian jessie versions +test:puppet37: + variables: + PUPPET_VERSION: "~> 3.7.2" + FACTER_VERSION: '~> 2.2.0' + <<: *job_definition + +test:puppet38_future_parser: + variables: + PUPPET_VERSION: '~> 3.8' + FACTER_VERSION: '~> 2.2.0' + FUTURE_PARSER: 'yes' + <<: *job_definition + +test:puppet40: + variables: + PUPPET_VERSION: "~> 4.0.0" + FACTER_VERSION: '~> 2.4.0' + <<: *job_definition + +# Default debia stretch versions +test:puppet45: + variables: + PUPPET_VERSION: "~> 4.5.2" + FACTER_VERSION: '~> 2.4.6' + <<: *job_definition + +# Latest greatest +test:puppet4x: + variables: + PUPPET_VERSION: "> 4" + FACTER_VERSION: '> 2' + <<: *job_definition + @@ -0,0 +1,22 @@ +source "https://rubygems.org" + +group :development, :unit_tests do + gem "rake" + gem "rspec-puppet", "~> 2.1", :require => false + gem "rspec-core", "3.1.7", :require => false + gem "puppetlabs_spec_helper" + gem "metadata-json-lint" + gem "rspec-puppet-facts" + gem "mocha" +end + +group :system_tests do + gem 'beaker' + gem 'beaker-rspec' + gem 'beaker_spec_helper' + gem 'serverspec' +end + +gem "puppet", ENV['PUPPET_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION'] || '~> 3.7.0' +gem "facter", ENV['FACTER_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION'] || '~> 2.2.0' + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..85326bb --- /dev/null +++ b/Rakefile @@ -0,0 +1,19 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Validate manifests, templates, and ruby files" +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +task :test => [:lint, :syntax , :validate, :spec] diff --git a/spec/classes/module_dir_spec.rb b/spec/classes/module_dir_spec.rb new file mode 100644 index 0000000..b33afc2 --- /dev/null +++ b/spec/classes/module_dir_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'common::moduledir', :type => :class do + let :pre_condition do + 'class { "common::moduledir": }' + end + let(:facts) { { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :debian_release => 'jessie', + :debian_codename => 'jessie', + :lsbdistcodename => 'jessie', + :virtual => 'physical', + :puppetversion => Puppet.version, } } + it { is_expected.to compile.with_all_deps } +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ba62e1..3cca63a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,12 @@ -require 'pathname' -dir = Pathname.new(__FILE__).parent -$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') -require 'puppet' -gem 'rspec', '>= 1.2.9' -require 'spec/autorun' +# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge +require 'puppetlabs_spec_helper/module_spec_helper' -Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file| - require support_file -end +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) + +RSpec.configure do |c| + + c.manifest_dir = File.join(fixture_path, 'manifests') + c.module_path = File.join(fixture_path, 'modules') -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should + c.color = true end |