Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Jul 2, 2014
1 parent 942affa commit d6046c1
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .fixtures.yml
@@ -0,0 +1,3 @@
fixtures:
symlinks:
ssh: "#{source_dir}"
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
Gemfile.lock
*.swp
37 changes: 37 additions & 0 deletions .travis.yml
@@ -0,0 +1,37 @@
language: ruby
bundler_args: --without development
script:
- bundle exec rake spec SPEC_OPTS='--format documentation'
- bundle exec rake lint
rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- 2.1.2
env:
- PUPPET_GEM_VERSION="~> 2.7.0"
- PUPPET_GEM_VERSION="~> 3.1.0"
- PUPPET_GEM_VERSION="~> 3.2.0"
- PUPPET_GEM_VERSION="~> 3.3.0"
- PUPPET_GEM_VERSION="~> 3.4.0"
- PUPPET_GEM_VERSION="~> 3.5.0"
- PUPPET_GEM_VERSION="~> 3.6.0"
matrix:
fast_finish: true
exclude:
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.1.2
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.1.2
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.1.2
env: PUPPET_GEM_VERSION="~> 3.2.0"
- rvm: 2.1.2
env: PUPPET_GEM_VERSION="~> 3.3.0"
- rvm: 2.1.2
env: PUPPET_GEM_VERSION="~> 3.4.0"
12 changes: 12 additions & 0 deletions Gemfile
@@ -0,0 +1,12 @@
source 'https://rubygems.org'

group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
22 changes: 22 additions & 0 deletions Rakefile
@@ -0,0 +1,22 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
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 =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end

PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.fail_on_warnings = true
task :default => [:spec, :lint, :validate]
8 changes: 8 additions & 0 deletions spec/classes/ssh_spec.rb
@@ -0,0 +1,8 @@
require 'spec_helper'

describe 'ssh' do
let(:facts) {{
:osfamily => 'Debian',
}}
it { should compile.with_all_deps }
end
25 changes: 25 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,25 @@
require 'puppetlabs_spec_helper/module_spec_helper'

RSpec.configure do |c|
c.include PuppetlabsSpec::Files

c.before :each do
# Ensure that we don't accidentally cache facts and environment
# between test cases.
Facter::Util::Loader.any_instance.stubs(:load_all)
Facter.clear
Facter.clear_messages

# Store any environment variables away to be restored later
@old_env = {}
ENV.each_key {|k| @old_env[k] = ENV[k]}

if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5')
Puppet.settings[:strict_variables]=true
end
end

c.after :each do
PuppetlabsSpec::Files.cleanup
end
end

0 comments on commit d6046c1

Please sign in to comment.