summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/nodesets/default.yml19
-rw-r--r--spec/classes/base_spec.rb44
-rw-r--r--spec/classes/daemon_spec.rb31
-rw-r--r--spec/classes/init_spec.rb27
-rw-r--r--spec/classes/onionbalance_spec.rb60
-rw-r--r--spec/defines/daemon_onion_service_spec.rb120
-rw-r--r--spec/functions/generate_onion_key_spec.rb73
-rw-r--r--spec/functions/onion_address_spec.rb48
-rw-r--r--spec/puppetlabs_spec_helper_clone.rb34
-rwxr-xr-x[-rw-r--r--]spec/spec_helper.rb48
-rw-r--r--spec/spec_helper_acceptance.rb18
-rw-r--r--spec/tmp/.keep0
12 files changed, 479 insertions, 43 deletions
diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml
deleted file mode 100644
index f09ad62..0000000
--- a/spec/acceptance/nodesets/default.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-HOSTS:
- debian-8-x64:
- platform: debian-8-amd64
- image: debian:8
- hypervisor: docker
- docker_preserve_image: true
- docker_cmd: '["/sbin/init"]'
- docker_image_commands:
- - 'apt-get install -y wget locales-all puppet git'
- - 'rm -f /usr/sbin/policy-rc.d'
-
-CONFIG:
- type: foss
- #log_level: verbose
- #log_level: debug
-
-ssh:
- password: root
- auth_methods: ["password"]
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
diff --git a/spec/classes/onionbalance_spec.rb b/spec/classes/onionbalance_spec.rb
new file mode 100644
index 0000000..ff9bb27
--- /dev/null
+++ b/spec/classes/onionbalance_spec.rb
@@ -0,0 +1,60 @@
+require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
+
+describe 'tor::onionbalance', :type => 'class' do
+ let(:default_facts) {
+ {
+ :osfamily => 'RedHat',
+ :operatingsystem => 'CentOS',
+ }
+ }
+ let(:facts){ default_facts }
+ let(:pre_condition){'Exec{path => "/bin"}' }
+ let(:params){
+ {
+ :services => {
+ 'keyname_of_service1' => {
+ 'name1' => 'onionservice_addr_3',
+ 'name2' => 'onionservice_addr_2',
+ '_key_content' => 'content_of_key_of_onionbalanced_service1',
+ },
+ },
+ }
+ }
+ describe 'with standard' do
+ it { is_expected.to compile.with_all_deps }
+
+ it { is_expected.to contain_package('python2-onionbalance').with(
+ :ensure => 'installed',
+ ) }
+ it { is_expected.to contain_service('tor@onionbalance').with(
+ :ensure => 'running',
+ :enable => true,
+ ) }
+ it { is_expected.to contain_service('onionbalance').with(
+ :ensure => 'running',
+ :enable => true,
+ :subscribe => 'Service[tor@onionbalance]',
+ ) }
+ context 'on Debian' do
+ let(:facts) {
+ {
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ }
+ }
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_package('onionbalance').with(
+ :ensure => 'installed',
+ ) }
+ it { is_expected.to contain_service('tor@onionbalance').with(
+ :ensure => 'running',
+ :enable => true,
+ ) }
+ it { is_expected.to contain_service('onionbalance').with(
+ :ensure => 'running',
+ :enable => true,
+ :subscribe => 'Service[tor@onionbalance]',
+ ) }
+ end
+ end
+end
diff --git a/spec/defines/daemon_onion_service_spec.rb b/spec/defines/daemon_onion_service_spec.rb
new file mode 100644
index 0000000..95be8c4
--- /dev/null
+++ b/spec/defines/daemon_onion_service_spec.rb
@@ -0,0 +1,120 @@
+require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
+require 'openssl'
+
+describe 'tor::daemon::onion_service', :type => 'define' do
+ let(:default_facts) {
+ {
+ :osfamily => 'RedHat',
+ :operatingsystem => 'CentOS',
+ }
+ }
+ let(:title){ 'test_os' }
+ let(:facts){ default_facts }
+ let(:pre_condition){'Exec{path => "/bin"}
+ include tor::daemon' }
+ describe 'with standard' do
+ it { is_expected.to compile.with_all_deps }
+
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with(
+ :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/,
+ :order => '05',
+ :target => '/etc/tor/torrc',
+ )}
+ it { is_expected.to_not contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort/) }
+ it { is_expected.to_not contain_file('/var/lib/tor/test_os') }
+ context 'on Debian' do
+ let(:facts) {
+ {
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ }
+ }
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with(
+ :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/,
+ :order => '05',
+ :target => '/etc/tor/torrc',
+ )}
+ it { is_expected.to_not contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort/) }
+ it { is_expected.to_not contain_file('/var/lib/tor/test_os') }
+ end
+ context 'with differt port params' do
+ let(:params){
+ {
+ :ports => ['25','443 192.168.0.1:8443']
+ }
+ }
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 25 127.0.0.1:25/) }
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 443 192.168.0.1:8443/) }
+ it { is_expected.to_not contain_file('/var/lib/tor/test_os') }
+ end
+ context 'with private_key' do
+ let(:params){
+ {
+ :ports => ['80'],
+ :private_key => OpenSSL::PKey::RSA.generate(1024).to_s,
+ }
+ }
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) }
+ it { is_expected.to contain_file('/var/lib/tor/test_os').with(
+ :ensure => 'directory',
+ :purge => true,
+ :force => true,
+ :recurse => true,
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :require => 'Package[tor]',
+ )}
+ it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with(
+ :content => /^[a-z2-7]{16}\.onion\n/,
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :notify => 'Service[tor]',
+ )}
+ it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with(
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :notify => 'Service[tor]',
+ )}
+ end
+ context 'with private key to generate' do
+ let(:params){
+ {
+ :ports => ['80'],
+ :private_key_name => 'test_os',
+ :private_key_store_path => File.expand_path(File.join(File.dirname(__FILE__),'..','tmp')),
+ }
+ }
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) }
+ it { is_expected.to contain_file('/var/lib/tor/test_os').with(
+ :ensure => 'directory',
+ :purge => true,
+ :force => true,
+ :recurse => true,
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :require => 'Package[tor]',
+ )}
+ it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with(
+ :content => /^[a-z2-7]{16}\.onion\n/,
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :notify => 'Service[tor]',
+ )}
+ it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with(
+ :owner => 'toranon',
+ :group => 'toranon',
+ :mode => '0600',
+ :notify => 'Service[tor]',
+ )}
+ end
+ end
+end
diff --git a/spec/functions/generate_onion_key_spec.rb b/spec/functions/generate_onion_key_spec.rb
new file mode 100644
index 0000000..355f862
--- /dev/null
+++ b/spec/functions/generate_onion_key_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+require 'fileutils'
+
+describe 'generate_onion_key' do
+ before(:all) do
+ @tmp_path = File.expand_path(File.join(File.dirname(__FILE__),'..','fixtures','tmp'))
+ @test_path = File.join(@tmp_path,'test.key')
+ @drpsyff5srkctr7h_str = "-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC9OUBOkL73n43ogC/Jma54/ZZDEpoisqpkGJHgbcRGJIxcqqfL
+PbnT3hD5SUCVXxLnzWDCTwTe2VOzIUlBXmslwVXnCJh/XGZg9NHiNU3EAZTwu1g9
+8gNmmG1bymaoEBkuC1osijOj+CN+gzLzApiMbDxddpxTn70LWaSqMDbfdQIDAQAB
+An88nBn9EGAa8QCDeIvWB2PbXV7EHTFB6/ioFzairIYx8YMEK6WTdDIRqw/EybHm
+Jo3nseFMXAMzXmlw9zh/t76ZzE7ooYocSPIEzpu4gDRsa5/mqRCGajs8A8ooiHN5
+Tc9cHzIfhjOYhu3VxF0G9LTAC8nKdWQkHm+h+J6A6+wBAkEA2E6GcIdPGTSfaNRS
+BHOpKUUSvH7W0e5fyYe221EhESdTFjVkaO5YN9HvcqYh27nik0azKgNj6PiE01FC
+0q4fgQJBAN/ycGS3dX5WRXEOpbQ04LKyxCFMVgS+tN5ueDgbv/SxWAxidLYcVfbg
+CcUA+L2OaQ95S97CxYlCLda10vIPOfUCQQCUvQJzFIgOlAHdqsovJ3011Lp6hVmg
+h6K0SK8zhkkPq5PVnKdMBEEDOUfG9XgoyFyF20LN7ADirSlgyesCRhuBAkEAmuCE
+MmNecn0fkUzb9IENVQik85JjeuyZEau8oLEwU/3CMu50YO2/1fijSQee/xlaN0Vf
+3zM8geyu3urodFdrcQJBAMBcecMvo4ddZ/GnwpKJuXEhKSwQfPOeb8lK12NvKuVE
+znq+qT/KbJlwy/27X/auCAzD5rJ9VVzyWiu8nnwICS8=
+-----END RSA PRIVATE KEY-----\n"
+ end
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /requires 2 arguments/) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /requires 2 arguments/) }
+ it { is_expected.to run.with_params('/etc/passwd','test').and_raise_error(Puppet::ParseError, /requires location \(\/etc\/passwd\) to be a directory/) }
+ describe 'with a key bigger than 1024' do
+ before(:each) do
+ FileUtils.mkdir_p(@tmp_path) unless File.directory?(@tmp_path)
+ File.open(@test_path,'w'){|f| f << OpenSSL::PKey::RSA.generate(2048) }
+ end
+ it { is_expected.to run.with_params(@tmp_path,'test').and_raise_error(Puppet::ParseError, /must have a length of 1024bit/) }
+ end
+ end
+
+ describe 'normal operation' do
+ before(:all) do
+ FileUtils.rm_rf(@tmp_path) if File.exists?(@tmp_path)
+ FileUtils.mkdir_p(@tmp_path)
+ end
+ after(:all) do
+ FileUtils.rm_rf(@tmp_path) if File.exists?(@tmp_path)
+ end
+ let(:return_value) {
+ scope.function_generate_onion_key([@tmp_path,'test'])
+ }
+ context 'without an existing key' do
+ it 'returns an onion address and a key ' do
+ expect(return_value.size).to be(2)
+ end
+ it 'creates and stores the key' do
+ expect(return_value.last).to be_eql(File.read(File.join(@tmp_path,'test.key')))
+ end
+ it 'returns a proper onion address' do
+ expect(return_value.first).to be_eql(scope.function_onion_address([File.read(File.join(@tmp_path,'test.key'))]))
+ end
+ it 'does not recreate a key once created' do
+ expect(scope.function_generate_onion_key([@tmp_path,'test'])).to be_eql(scope.function_generate_onion_key([@tmp_path,'test']))
+ end
+ it 'creates to different keys for different names' do
+ expect(scope.function_generate_onion_key([@tmp_path,'test']).first).to_not be_eql(scope.function_generate_onion_key([@tmp_path,'test2']))
+ end
+ end
+ context 'with an existing key' do
+ before(:all) do
+ File.open(File.join(@tmp_path,'test3.key'),'w'){|f| f << @drpsyff5srkctr7h_str }
+ end
+ it { is_expected.to run.with_params(@tmp_path,'test3').and_return(['drpsyff5srkctr7h',@drpsyff5srkctr7h_str]) }
+ end
+ end
+end
diff --git a/spec/functions/onion_address_spec.rb b/spec/functions/onion_address_spec.rb
new file mode 100644
index 0000000..942d022
--- /dev/null
+++ b/spec/functions/onion_address_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+
+describe 'onion_address' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /requires 1 argument/) }
+ it { is_expected.to run.with_params(1,2).and_raise_error(Puppet::ParseError, /requires 1 argument/) }
+ end
+
+ describe 'normal operation' do
+ it { is_expected.to run.with_params(
+"-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC9OUBOkL73n43ogC/Jma54/ZZDEpoisqpkGJHgbcRGJIxcqqfL
+PbnT3hD5SUCVXxLnzWDCTwTe2VOzIUlBXmslwVXnCJh/XGZg9NHiNU3EAZTwu1g9
+8gNmmG1bymaoEBkuC1osijOj+CN+gzLzApiMbDxddpxTn70LWaSqMDbfdQIDAQAB
+An88nBn9EGAa8QCDeIvWB2PbXV7EHTFB6/ioFzairIYx8YMEK6WTdDIRqw/EybHm
+Jo3nseFMXAMzXmlw9zh/t76ZzE7ooYocSPIEzpu4gDRsa5/mqRCGajs8A8ooiHN5
+Tc9cHzIfhjOYhu3VxF0G9LTAC8nKdWQkHm+h+J6A6+wBAkEA2E6GcIdPGTSfaNRS
+BHOpKUUSvH7W0e5fyYe221EhESdTFjVkaO5YN9HvcqYh27nik0azKgNj6PiE01FC
+0q4fgQJBAN/ycGS3dX5WRXEOpbQ04LKyxCFMVgS+tN5ueDgbv/SxWAxidLYcVfbg
+CcUA+L2OaQ95S97CxYlCLda10vIPOfUCQQCUvQJzFIgOlAHdqsovJ3011Lp6hVmg
+h6K0SK8zhkkPq5PVnKdMBEEDOUfG9XgoyFyF20LN7ADirSlgyesCRhuBAkEAmuCE
+MmNecn0fkUzb9IENVQik85JjeuyZEau8oLEwU/3CMu50YO2/1fijSQee/xlaN0Vf
+3zM8geyu3urodFdrcQJBAMBcecMvo4ddZ/GnwpKJuXEhKSwQfPOeb8lK12NvKuVE
+znq+qT/KbJlwy/27X/auCAzD5rJ9VVzyWiu8nnwICS8=
+-----END RSA PRIVATE KEY-----"
+ ).and_return("drpsyff5srkctr7h")}
+ end
+ describe 'by getting an RSA key' do
+ it { is_expected.to run.with_params(OpenSSL::PKey::RSA.new(
+"-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQDbvYjbtJB9vTnEygyq4Bzp0xxtTl3ZYKC6JbxgRzP8uLv1HoxX
+20EmQUZ/LNBXHebc6frlObhtpKULFuBzAy5LpdKI9CUErkl3D3AigFgP3XP/PtdP
+m11TuxdBoKL6Jbo54NpUVOGQ5SJJaNEOfhmgMSCtlyyI9DBni3PLO2P0sQIDAQAB
+AoGAPTlt7Gk+6QnUErSJGwMeize67+mp1GtL3RGujtTH8141YHKGf+QjHtmJHt4J
+nnxCWsMGmN+gN0xsf8578w+r0fvDjZ3e5lVUpR/8ds90a654Lr/pgqLc3H1EZ9Pr
+GDFjPdaMtdTSX5hSAB2EDLfDUU19bdFRK+k71mglrMLpdQECQQDmJt3mmX67kAzH
+w2I/BEbmOlonmn3c98VyawoNrk0fKAluoYWHxxk9SuCu2ZDQyyPKPQuZbgdPnUNp
+kV3PuQ6ZAkEA9GtTjMfceX8ArLTmOMIMVP2t8yzbcK2uqukMG79JiPZbYKIstjho
+XUpO/jZhTb9p8M4NV/09z091gMTOF6Fd2QJBAM1I7bS6ROhX3I5yIDfFQNgqRC//
+BTULa/par2T0i6W2uHMNb2VkmYaqOy66sQkLqKjDOo1oLu08gNyw5NRbZEECQQCr
+FDR25a28nNisCjLap3haRPXssAko5WjM2DJReaLO6yEqklkZcoIaSljgNtAEy2Yr
+1w4f+HG7GbL1XsuiXqCBAkAeYljaIVhqGOOez0ORaCm0FCLoTJ6/fn7009os/qgr
+n2xsVGUNm+E0pvAMT0LIx2KvpLxe2Y0Xx497/vyM6e7G
+-----END RSA PRIVATE KEY-----")
+ ).and_return("d3ep6pcs4to4hbwo") }
+ end
+end
diff --git a/spec/puppetlabs_spec_helper_clone.rb b/spec/puppetlabs_spec_helper_clone.rb
new file mode 100644
index 0000000..6a94a3b
--- /dev/null
+++ b/spec/puppetlabs_spec_helper_clone.rb
@@ -0,0 +1,34 @@
+#This file pulls in only the minimum necessary to let unmigrated specs still work
+
+# Define the main module namespace for use by the helper modules
+module PuppetlabsSpec
+ # FIXTURE_DIR represents the standard locations of all fixture data. Normally
+ # this represents <project>/spec/fixtures. This will be used by the fixtures
+ # library to find relative fixture data.
+ FIXTURE_DIR = File.join("spec", "fixtures") unless defined?(FIXTURE_DIR)
+end
+
+# Require all necessary helper libraries so they can be used later
+require 'puppetlabs_spec_helper/puppetlabs_spec/files'
+require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures'
+#require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
+require 'puppetlabs_spec_helper/puppetlabs_spec/matchers'
+
+RSpec.configure do |config|
+ # Include PuppetlabsSpec helpers so they can be called at convenience
+ config.extend PuppetlabsSpec::Files
+ config.extend PuppetlabsSpec::Fixtures
+ config.include PuppetlabsSpec::Fixtures
+
+ config.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'
+ config.strict_variables = true if ENV['STRICT_VARIABLES'] == 'yes'
+ config.stringify_facts = false if ENV['STRINGIFY_FACTS'] == 'no'
+ config.trusted_node_data = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
+ config.ordering = ENV['ORDERING'] if ENV['ORDERING']
+
+ # This will cleanup any files that were created with tmpdir or tmpfile
+ config.after :each do
+ PuppetlabsSpec::Files.cleanup
+ end
+end
+
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3cca63a..66cfb3b 100644..100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,12 +1,48 @@
-# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge
+#! /usr/bin/env ruby -S rspec
+dir = File.expand_path(File.dirname(__FILE__))
+$LOAD_PATH.unshift File.join(dir, 'lib')
+
+# So everyone else doesn't have to include this base constant.
+module PuppetSpec
+ FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
+end
+
+require 'puppet'
+require 'rspec-puppet'
require 'puppetlabs_spec_helper/module_spec_helper'
+require 'mocha/api'
+#require 'puppetlabs_spec_helper/module_spec_helper'
+require 'puppetlabs_spec_helper_clone'
+
+# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples
+RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers)
-fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+RSpec.configure do |config|
+ config.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules')
+ config.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests')
+ config.environmentpath = spec_path = File.expand_path(File.join(Dir.pwd, 'spec'))
-RSpec.configure do |c|
+ config.add_setting :puppet_future
+ #config.puppet_future = (ENV['FUTURE_PARSER'] == 'yes' or Puppet.version.to_f >= 4.0)
+ config.puppet_future = Puppet.version.to_f >= 4.0
- c.manifest_dir = File.join(fixture_path, 'manifests')
- c.module_path = File.join(fixture_path, 'modules')
+ config.before :each do
+ # Ensure that we don't accidentally cache facts and environment between
+ # test cases. This requires each example group to explicitly load the
+ # facts being exercised with something like
+ # Facter.collection.loader.load(:ipaddress)
+ Facter.clear
+ Facter.clear_messages
+
+ RSpec::Mocks.setup
+ end
+
+ config.after :each do
+ RSpec::Mocks.verify
+ RSpec::Mocks.teardown
+ end
+end
- c.color = true
+# Helper class to test handling of arguments which are derived from string
+class AlsoString < String
end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
deleted file mode 100644
index e6a2cd8..0000000
--- a/spec/spec_helper_acceptance.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'beaker-rspec'
-
-RSpec.configure do |c|
- module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
- module_name = module_root.split('-').last
-
- # Readable test descriptions
- c.formatter = :documentation
-
- # Configure all nodes in nodeset
- c.before :suite do
- # Install module and dependencies
- puppet_module_install(:source => module_root, :module_name => module_name)
- hosts.each do |host|
- shell('git clone https://github.com/puppetlabs/puppetlabs-concat.git /etc/puppet/modules/concat')
- end
- end
-end
diff --git a/spec/tmp/.keep b/spec/tmp/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spec/tmp/.keep