From a41031a7e26f452ac4f15664d85f5f4568f52780 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Tue, 24 Mar 2020 01:47:31 +0100 Subject: [PATCH] add metadata to module --- Gemfile | 18 ++++++++++++++++++ Rakefile | 32 ++++++++++++++++++++++++++++++++ examples/init.pp | 12 ++++++++++++ metadata.json | 17 +++++++++++++++++ spec/classes/init_spec.rb | 6 ++++++ spec/spec_helper.rb | 1 + 6 files changed, 86 insertions(+) create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 examples/init.pp create mode 100644 metadata.json create mode 100644 spec/classes/init_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4333d23 --- /dev/null +++ b/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.2.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..df59df7 --- /dev/null +++ b/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +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 =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run lint, validate, and spec tests.' +task :test do + [:lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/examples/init.pp b/examples/init.pp new file mode 100644 index 0000000..23f3236 --- /dev/null +++ b/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Inc. is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://puppet.com/docs/puppet/latest/bgtm.html#testing-your-module +# +include ::sudo diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..412fd93 --- /dev/null +++ b/metadata.json @@ -0,0 +1,17 @@ +{ + "name": "madduck-sudo", + "version": "0.1.0", + "author": "madduck", + "summary": "Manage sudo settings/aliases/rules in sudoers.d files", + "license": "Apache-2.0", + "source": "https://git.madduck.net/puppet/sudo.git", + "project_page": "https://git.madduck.net/puppet/sudo.git/blob/HEAD:/README.md", + "issues_url": "mailto:patches@git.madduck.net", + "dependencies": [ + { + "name": "puppetlabs-stdlib", + "version_requirement": ">= 1.0.0" + } + ], + "data_provider": null +} diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..b911e76 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'sudo' do + context 'with default values for all parameters' do + it { should contain_class('sudo') } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' -- 2.39.5