diff --git a/.gitignore b/.gitignore index 5e135f2..e9b3cf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,20 @@ pkg/ Gemfile.lock Gemfile.local vendor/ .vendor/ spec/fixtures/manifests/ spec/fixtures/modules/ .vagrant/ .bundle/ .ruby-version coverage/ log/ .idea/ .dependencies/ .librarian/ Puppetfile.lock *.iml .*.sw? .yardoc/ Guardfile -spec/fixtures/tmpdir/ diff --git a/.sync.yml b/.sync.yml index 0644836..835ef80 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,8 +1,3 @@ --- .travis.yml: secure: "IkrfAnec7ovZLMvhvXt8ZihyYdAJTC/nm7KDm4u2G/uD2NGaMdHNOAenkwIwC1vfCzHKcgC5u/lAYFrYvHpQpJW0kHLKnk1SpndfWX9kd5SlDDzEP5mJGjMZeTY6H9sV5fsB6Pt7l/sw5ACL/0bFDl0mYBnVhGv6UxZZ5xMQIUw=" -spec/spec_helper.rb: - spec_overrides: "require 'spec_helper_methods'" -.gitignore: - paths: - - spec/fixtures/tmpdir/ diff --git a/functions/dir_split.pp b/functions/dir_split.pp index 47429db..b74ae74 100644 --- a/functions/dir_split.pp +++ b/functions/dir_split.pp @@ -1,25 +1,25 @@ # @summary Splits the given directory or directories into individual paths. # # Use this function when you need to split a absolute path into multiple absolute paths # that all descend from the given path. # # @param dirs [Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]] - either an absolute path or a array of absolute paths. # @return [Array[String]] - an array of absolute paths after being cut into individual paths. # @example calling the function # extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs'] function extlib::dir_split(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs) >> Array[String] { $sep = extlib::file_separator() $dirs_array = [$dirs].flatten.unique.map | Stdlib::Absolutepath $dir | { $dir.split(shell_escape($sep)).reduce([]) |Array $acc, $value | { - $counter = $acc.length - 1 - $acc_value = ($acc[$counter] =~ Undef) ? { true => '', false => $acc[$counter] } - unless empty($value) { - $acc + extlib::path_join([$acc_value, $value]) - } else { - $acc - } + $counter = $acc.length - 1 + $acc_value = ($acc[$counter] =~ Undef) ? { true => '', false => $acc[$counter] } + unless empty($value) { + $acc + extlib::path_join([$acc_value, $value]) + } else { + $acc } + } } $dirs_array.flatten.unique } diff --git a/functions/mkdir_p.pp b/functions/mkdir_p.pp index f198e1c..ddefe56 100644 --- a/functions/mkdir_p.pp +++ b/functions/mkdir_p.pp @@ -1,20 +1,20 @@ # @summary Like the unix command mkdir_p except with puppet code. # This creates file resources for all directories and utilizes the dir_split() function # to get a list of all the descendant directories. You will have no control over any other parameters # for the file resource. If you wish to control the file resources you can use the dir_split() function # and get an array of directories for use in your own code. Please note this does not use an exec resource. # # @param dirs [Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]] - the path(s) to create # @return [Array[Stdlib::Absolutepath]] # @example How to use # extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin'] # @note splits the given directories into paths that are then created using file resources # @note if you wish to create the directories manually you can use the extlib::dir_split() function in the same manner function extlib::mkdir_p(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs) >> Array[Stdlib::Absolutepath] { $dirs_array = extlib::dir_split($dirs) - @file{$dirs_array: + @file { $dirs_array: ensure => directory, } realize(File[$dirs_array]) $dirs_array } diff --git a/spec/functions/extlib/cache_data_spec.rb b/spec/functions/extlib/cache_data_spec.rb index c475263..ca504b7 100644 --- a/spec/functions/extlib/cache_data_spec.rb +++ b/spec/functions/extlib/cache_data_spec.rb @@ -1,40 +1,28 @@ require 'spec_helper' describe 'extlib::cache_data' do let(:initial_data) { 'original_password' } let(:data_name) { 'mysql_password' } let(:namespace) { 'data_cache' } - let(:vardir) { "#{FIXTURES_PATH}/tmpdir" } it { expect(subject).not_to eq(nil) } it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params(data_name).and_raise_error(ArgumentError) } it { is_expected.to run.with_params('', initial_data).and_raise_error(ArgumentError) } it { is_expected.to run.with_params('', 'mysql_password', initial_data).and_raise_error(ArgumentError) } describe 'data caching' do - before do - # Fool rspec-puppet into creating a consistent vardir for these tests! - allow(Dir).to receive(:mktmpdir).and_return("#{FIXTURES_PATH}/tmpdir") - # Stop rspec-puppet from blowing away the vardir between each example. Is unstubbed in the after block. - allow(FileUtils).to receive(:rm_rf).with(vardir).and_return(true) - end - after do - # Since rspec-puppet won't be removing the vardir, we'd better do that ourselves. - FileUtils.rm_rf(vardir) if File.directory?(vardir) - end - context 'when not in cache' do it 'returns supplied data' do is_expected.to run.with_params(namespace, data_name, initial_data).and_return(initial_data) end end context 'when cached' do it 'returns cached data' do is_expected.to run.with_params(namespace, data_name, initial_data).and_return(initial_data) is_expected.to run.with_params(namespace, data_name, 'new_password').and_return(initial_data) end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 927af0c..b2b2704 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,20 +1,18 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) if facts facts.each do |name, value| add_custom_fact name.to_sym, value end end end - -require 'spec_helper_methods' diff --git a/spec/spec_helper_methods.rb b/spec/spec_helper_methods.rb deleted file mode 100644 index f9724d4..0000000 --- a/spec/spec_helper_methods.rb +++ /dev/null @@ -1,5 +0,0 @@ -# From https://gist.github.com/stefanozanella/4190920 -# Make stdlib (i.e. its functions) available to rspec so our own functions that -# require stdlib functions can load them. -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'fixtures', 'modules', 'stdlib', 'lib') -FIXTURES_PATH = File.expand_path(File.join(__FILE__, '..', 'fixtures'))