aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-12-30 13:39:04 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-12-30 13:39:04 -0200
commit8a074424708a2ca7c7625e138fe29621ae3315a8 (patch)
tree0a1a47e55d7d49114cf246b9efea1e0907ee1cbd
parenta1bde593bf95ea1048a35ad6c42cbad8c7a51971 (diff)
parent6fcf75d46a5c7fcd00fd4470270552b543cf4452 (diff)
downloadpuppet-common-8a074424708a2ca7c7625e138fe29621ae3315a8.tar.gz
puppet-common-8a074424708a2ca7c7625e138fe29621ae3315a8.tar.bz2
Merge branch 'master' of https://gitlab.com/shared-puppet-modules-group/commonHEADmaster
-rw-r--r--.fixtures.yml3
-rw-r--r--.gitignore10
-rw-r--r--.gitlab-ci.yml48
-rw-r--r--Gemfile22
-rw-r--r--Rakefile19
-rw-r--r--lib/puppet/parser/functions/get_default.rb15
-rw-r--r--lib/puppet/parser/functions/hostname.rb13
-rw-r--r--manifests/module_dir.pp2
-rw-r--r--manifests/module_file.pp2
-rw-r--r--spec/classes/module_dir_spec.rb17
-rw-r--r--spec/spec_helper.rb22
11 files changed, 130 insertions, 43 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
+
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/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
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
-
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 {
diff --git a/manifests/module_file.pp b/manifests/module_file.pp
index b4c391f..31fc01e 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 {
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