From 2ac62545834f10e958c863adac75cbe47a597faf Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 4 Mar 2016 23:34:17 +0100 Subject: remove a crappy function --- lib/puppet/parser/functions/hostname.rb | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 lib/puppet/parser/functions/hostname.rb diff --git a/lib/puppet/parser/functions/hostname.rb b/lib/puppet/parser/functions/hostname.rb deleted file mode 100644 index 7bc477f..0000000 --- a/lib/puppet/parser/functions/hostname.rb +++ /dev/null @@ -1,13 +0,0 @@ -# get an uniq array of ipaddresses for a hostname -require 'resolv' - -module Puppet::Parser::Functions - newfunction(:hostname, :type => :rvalue) do |args| - res = Array.new - Resolv::DNS.new.each_address(args[0]){ |addr| - res << addr - } - res.uniq - end -end - -- cgit v1.2.3 From cff3734e4fc76973fd3720f1dd7f50a80e65d5f4 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 27 Mar 2016 18:33:24 +0200 Subject: this is the pick() function in stdlib --- lib/puppet/parser/functions/get_default.rb | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 lib/puppet/parser/functions/get_default.rb diff --git a/lib/puppet/parser/functions/get_default.rb b/lib/puppet/parser/functions/get_default.rb deleted file mode 100644 index 3f4359b..0000000 --- a/lib/puppet/parser/functions/get_default.rb +++ /dev/null @@ -1,15 +0,0 @@ -# get_default($value, $default) : $value -# -# return $value || $default. -module Puppet::Parser::Functions - newfunction(:get_default, :type => :rvalue) do |args| - value = nil - args.each { |x| - if ! x.nil? and x.length > 0 - value = x - break - end - } - return value - end -end -- cgit v1.2.3 From a27930d70e97291599cb45ba125bf90e8c432e55 Mon Sep 17 00:00:00 2001 From: varac Date: Thu, 3 Nov 2016 00:56:27 +0100 Subject: The file mode specification must be a string, not 'Fixnum' --- manifests/module_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/module_dir.pp b/manifests/module_dir.pp index 2420da9..2f55b65 100644 --- a/manifests/module_dir.pp +++ b/manifests/module_dir.pp @@ -18,7 +18,7 @@ define common::module_dir( $owner = root, $group = 0, - $mode = 0644 + $mode = '0644' ) { include common::moduledir file { -- cgit v1.2.3 From f4af02ee7a6d4d071506642bec1401662d1da964 Mon Sep 17 00:00:00 2001 From: varac Date: Thu, 3 Nov 2016 01:13:30 +0100 Subject: Add rspec skeleton --- .fixtures.yml | 3 +++ .gitignore | 10 +++++++++ .gitlab-ci.yml | 48 +++++++++++++++++++++++++++++++++++++++++ Gemfile | 22 +++++++++++++++++++ Rakefile | 19 ++++++++++++++++ spec/classes/module_dir_spec.rb | 17 +++++++++++++++ spec/spec_helper.rb | 22 ++++++++----------- 7 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 .fixtures.yml create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 spec/classes/module_dir_spec.rb 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 + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..44630f4 --- /dev/null +++ b/Gemfile @@ -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 -- cgit v1.2.3 From 6fcf75d46a5c7fcd00fd4470270552b543cf4452 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Thu, 16 Nov 2017 14:26:19 -0500 Subject: Fix file mode type in module_file --- manifests/module_file.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/module_file.pp b/manifests/module_file.pp index c1070bc..7e7f1bb 100644 --- a/manifests/module_file.pp +++ b/manifests/module_file.pp @@ -18,7 +18,7 @@ define common::module_file ( $source = undef, $owner = root, $group = 0, - $mode = 0644 + $mode = '0644' ){ include common::moduledir file { -- cgit v1.2.3