From 4510682dff23142df5de4cfcc988e4319fcb73cd Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 31 Oct 2016 23:15:18 +0100 Subject: add a default set of specs so that the minimum is tested --- Gemfile | 1 + Rakefile | 10 +++++++ metadata.json | 71 +++++++++++++++++++++++++++++++++++++++++++++ spec/classes/base_spec.rb | 44 ++++++++++++++++++++++++++++ spec/classes/daemon_spec.rb | 31 ++++++++++++++++++++ spec/classes/init_spec.rb | 27 +++++++++++++++++ 6 files changed, 184 insertions(+) create mode 100644 metadata.json create mode 100644 spec/classes/base_spec.rb create mode 100644 spec/classes/daemon_spec.rb create mode 100644 spec/classes/init_spec.rb diff --git a/Gemfile b/Gemfile index d4109b9..f182839 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ group :development, :unit_tests do # keep for its rake task for now gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', :require => false + gem 'librarian-puppet', :require => false gem 'metadata-json-lint', :require => false gem 'pry', :require => false gem 'simplecov', :require => false diff --git a/Rakefile b/Rakefile index e136b8e..0c37d3b 100644 --- a/Rakefile +++ b/Rakefile @@ -5,3 +5,13 @@ require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +# use librarian-puppet to manage fixtures instead of .fixtures.yml +# offers more possibilities like explicit version management, forge downloads,... +task :librarian_spec_prep do + sh "librarian-puppet install --path=spec/fixtures/modules/" + pwd = `pwd`.strip + unless File.directory?("#{pwd}/spec/fixtures/modules/tor") + sh "ln -s #{pwd} #{pwd}/spec/fixtures/modules/tor" + end +end +task :spec_prep => :librarian_spec_prep diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..d83f0cb --- /dev/null +++ b/metadata.json @@ -0,0 +1,71 @@ +{ + "name": "duritong-tor", + "version": "0.0.1", + "author": "duritong and others", + "summary": "Manage tor and its components", + "description": "Manage tor and its components", + "license": "GPLv3", + "source": "https://github.com/duritong/puppet-tor", + "project_page": "https://github.com/duritong/puppet-tor", + "issues_url": "https://github.com/duritong/puppet-tor/issues", + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7", + "8" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04", + "14.04", + "16.04" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">=2.7.20 <5.0.0" + } + ], + "dependencies": [ + { + "name": "puppetlabs-stdlib" + }, + { + "name": "puppetlabs-concat" + }, + { + "name": "puppetlabs-apt" + } + ] +} diff --git a/spec/classes/base_spec.rb b/spec/classes/base_spec.rb new file mode 100644 index 0000000..7f288ec --- /dev/null +++ b/spec/classes/base_spec.rb @@ -0,0 +1,44 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'tor::base', :type => 'class' do + let(:default_facts) { + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + } + } + let(:facts){ default_facts } + let(:pre_condition){'include ::tor + Exec{path => "/bin"}' } + describe 'with standard' do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_package('tor').with_ensure('installed') } + it { is_expected.to_not contain_package('tor-geoipdb').with_ensure('installed') } + it { is_expected.to contain_service('tor').with( + :ensure => 'running', + :enable => 'true', + :hasrestart => 'true', + :hasstatus => 'true', + :require => 'Package[tor]', + ) } + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_package('tor').with_ensure('installed') } + it { is_expected.to contain_package('tor-geoipdb').with_ensure('installed') } + it { is_expected.to contain_service('tor').with( + :ensure => 'running', + :enable => 'true', + :hasrestart => 'true', + :hasstatus => 'true', + :require => 'Package[tor]', + ) } + end + end +end diff --git a/spec/classes/daemon_spec.rb b/spec/classes/daemon_spec.rb new file mode 100644 index 0000000..db5291d --- /dev/null +++ b/spec/classes/daemon_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'tor::daemon', :type => 'class' do + let(:default_facts) { + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + } + } + let(:facts){ default_facts } + let(:pre_condition){'Exec{path => "/bin"}' } + describe 'with standard' do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_class('tor') } + it { is_expected.to contain_class('tor::daemon::base') } + it { is_expected.to_not contain_class('tor::munin') } + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('tor') } + it { is_expected.to contain_class('tor::daemon::base') } + it { is_expected.to_not contain_class('tor::munin') } + end + end +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..be4f30b --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'tor', :type => 'class' do + let(:default_facts) { + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + } + } + let(:facts){ default_facts } + let(:pre_condition){'Exec{path => "/bin"}' } + describe 'with standard' do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_class('tor::base') } + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('tor::base') } + end + end +end -- cgit v1.2.3