Skip to content

Commit

Permalink
Merge pull request petems#9 from fuero/rspec-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
davealden authored Jun 21, 2018
2 parents dbd8a79 + 481d183 commit 7bf6219
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 19 deletions.
20 changes: 4 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
modules/

# emacs turds
*\~
.*\~
\#*
.\#*

# macOS Finder turds
.DS_Store

# AppleDouble resource forks
._*

# Prevent accidental private key commits
.ssh
.bundle/
.idea/
coverage/
vendor/bundle
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format documentation
--color
36 changes: 36 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']

gem 'facter', '>= 1.7.0'
gem 'metadata-json-lint'
gem 'puppet', puppetversion
gem 'rake'
gem 'rubocop'
gem 'vault'

# # 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

group :development do
gem 'puppet-lint', '>= 1.0.0'
gem 'ruby-debug-ide'
end

group :test do
gem 'puppetlabs_spec_helper', '>= 1.2.0'

gem 'rspec'
gem 'rspec-puppet'
gem 'rspec-puppet-utils'

gem 'simplecov'
gem 'simplecov-console'
end

112 changes: 112 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ansi (1.5.0)
ast (2.4.0)
aws-sigv4 (1.0.2)
diff-lcs (1.3)
docile (1.3.0)
facter (2.5.1)
fast_gettext (1.1.2)
hiera (3.4.2)
hirb (0.7.3)
json (2.1.0)
json-schema (2.8.0)
addressable (>= 2.4)
locale (2.1.2)
metaclass (0.0.4)
metadata-json-lint (2.1.0)
json-schema (~> 2.8)
spdx-licenses (~> 1.0)
mocha (1.4.0)
metaclass (~> 0.0.1)
multi_json (1.13.1)
parallel (1.12.1)
parser (2.5.0.5)
ast (~> 2.4.0)
powerpack (0.1.1)
public_suffix (3.0.2)
puppet (5.5.0)
facter (> 2.0.1, < 4)
fast_gettext (~> 1.1.2)
hiera (>= 3.2.1, < 4)
locale (~> 2.1)
multi_json (~> 1.10)
puppet-lint (2.3.3)
puppet-syntax (2.4.1)
rake
puppetlabs_spec_helper (2.6.2)
mocha (~> 1.0)
puppet-lint (~> 2.0)
puppet-syntax (~> 2.0)
rspec-puppet (~> 2.0)
rainbow (3.0.0)
rake (12.3.1)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-puppet (2.6.11)
rspec
rspec-puppet-utils (3.4.0)
mocha
puppet
puppetlabs_spec_helper
rspec
rspec-puppet
rspec-support (3.7.1)
rubocop (0.54.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-debug-ide (0.6.1)
rake (>= 0.8.1)
ruby-progressbar (1.9.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-console (0.4.2)
ansi
hirb
simplecov
simplecov-html (0.10.2)
spdx-licenses (1.1.0)
unicode-display_width (1.3.0)
vault (0.11.0)
aws-sigv4

PLATFORMS
ruby

DEPENDENCIES
facter (>= 1.7.0)
metadata-json-lint
puppet (>= 3.3)
puppet-lint (>= 1.0.0)
puppetlabs_spec_helper (>= 1.2.0)
rake
rspec
rspec-puppet
rspec-puppet-utils
rubocop
ruby-debug-ide
simplecov
simplecov-console
vault

BUNDLED WITH
1.16.1
32 changes: 32 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/puppet/functions/hiera_vault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def lookup_key(key, options, context)
def vault_get(key, options, context)

if ! ['string','json',nil].include?(options['default_field_parse'])
raise ArgumentError, "[hiera-vault] invalid value for default_field_parse: '#{options['default_field_behavior']}', should be one of 'string','json'"
raise ArgumentError, "[hiera-vault] invalid value for default_field_parse: '#{options['default_field_parse']}', should be one of 'string','json'"
end

if ! ['ignore','only',nil].include?(options['default_field_behavior'])
Expand Down Expand Up @@ -122,8 +122,8 @@ def vault_get(key, options, context)
next if secret.nil?

context.explain { "[hiera-vault] Read secret: #{key}" }
if (options['default_field'] && ['ignore', nil].include?(options['default_field_behavior'])) ||
(secret.data.has_key?(options['default_field'].to_sym) && secret.data.length == 1)
if (options['default_field'] and ( ['ignore', nil].include?(options['default_field_behavior']) ||
(secret.data.has_key?(options['default_field'].to_sym) && secret.data.length == 1) ) )

return nil if ! secret.data.has_key?(options['default_field'].to_sym)

Expand Down
Loading

0 comments on commit 7bf6219

Please sign in to comment.