From bff4ad619ffb7aad26bc721b47206eef8927d187 Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Tue, 4 Mar 2014 16:11:09 +0100 Subject: [PATCH 1/5] fix $ensure to actually do what I expect. --- manifests/client/install.pp | 4 +--- manifests/server/install.pp | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 6429f1563..7c21342a1 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -1,6 +1,4 @@ -class ssh::client::install ( - $ensure = present -) { +class ssh::client::install if !defined(Package[$ssh::params::client_package_name]) { package { $ssh::params::client_package_name: ensure => $ensure, diff --git a/manifests/server/install.pp b/manifests/server/install.pp index a4c725e75..65ea9bdbe 100644 --- a/manifests/server/install.pp +++ b/manifests/server/install.pp @@ -1,10 +1,10 @@ -class ssh::server::install ( - $ensure = present -) { +class ssh::server::install include ssh::params if !defined(Package[$ssh::params::server_package_name]) { package { $ssh::params::server_package_name: - ensure => $ensure, + ensure => $ensure, + blahblah => $ensure, + } } } From dbabc49c150abe8f532c2eebc865a3e131e81c85 Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Tue, 4 Mar 2014 16:34:22 +0100 Subject: [PATCH 2/5] fix syntax --- manifests/client/install.pp | 4 ++-- manifests/server/install.pp | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 7c21342a1..6d7362dcd 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -1,7 +1,7 @@ -class ssh::client::install +class ssh::client::install { if !defined(Package[$ssh::params::client_package_name]) { package { $ssh::params::client_package_name: - ensure => $ensure, + ensure => $ssh::client::ensure, } } } diff --git a/manifests/server/install.pp b/manifests/server/install.pp index 65ea9bdbe..6d88157b5 100644 --- a/manifests/server/install.pp +++ b/manifests/server/install.pp @@ -1,10 +1,8 @@ -class ssh::server::install +class ssh::server::install { include ssh::params if !defined(Package[$ssh::params::server_package_name]) { package { $ssh::params::server_package_name: - ensure => $ensure, - blahblah => $ensure, - + ensure => $ssh::server::ensure, } } } From 93256508fad11df7e28fe551957ed843add71dde Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Tue, 4 Mar 2014 16:42:08 +0100 Subject: [PATCH 3/5] re-instate check for package name --- manifests/client/install.pp | 8 +++++--- manifests/server/install.pp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 6d7362dcd..86771d770 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -1,7 +1,9 @@ class ssh::client::install { - if !defined(Package[$ssh::params::client_package_name]) { - package { $ssh::params::client_package_name: - ensure => $ssh::client::ensure, + if $ssh::params::client_package_name { + if !defined(Package[$ssh::params::client_package_name]) { + package { $ssh::params::client_package_name: + ensure => $ssh::client::ensure, + } } } } diff --git a/manifests/server/install.pp b/manifests/server/install.pp index 6d88157b5..58b5ca1d3 100644 --- a/manifests/server/install.pp +++ b/manifests/server/install.pp @@ -1,8 +1,10 @@ class ssh::server::install { include ssh::params - if !defined(Package[$ssh::params::server_package_name]) { - package { $ssh::params::server_package_name: - ensure => $ssh::server::ensure, + if $ssh::params::server_package_name { + if !defined(Package[$ssh::params::server_package_name]) { + package { $ssh::params::server_package_name: + ensure => $ssh::server::ensure, + } } } } From 2d3c573139786393a6a79a359c1fc41af5f43a47 Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Tue, 4 Mar 2014 17:30:42 +0100 Subject: [PATCH 4/5] Set up a few simple tests --- spec/spec_helper.rb | 20 ++------------------ tests/init.pp | 2 +- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4aeeae23..6e1d96819 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,2 @@ -require 'pathname' -dir = Pathname.new(__FILE__).parent -$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') - -require 'mocha' -require 'puppet' -gem 'rspec', '=1.2.9' -require 'spec/autorun' - -Spec::Runner.configure do |config| - config.mock_with :mocha -end - -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end +require 'rspec-puppet' +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/tests/init.pp b/tests/init.pp index 13a463808..1c7d29f18 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1 +1 @@ -include ssh +class {"::ssh::server": } From 5ff3d28e77ebbc58e7d38c2760f2689de389561d Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Tue, 4 Mar 2014 17:31:53 +0100 Subject: [PATCH 5/5] Add testing files --- .fixtures.yml | 3 +++ .gemfile | 16 ++++++++++++++ .travis.yml | 14 ++++++++++++ Rakefile | 2 ++ manifests/site.pp | 0 spec/classes/client_spec.rb | 33 +++++++++++++++++++++++++++++ spec/classes/server_spec.rb | 33 +++++++++++++++++++++++++++++ spec/fixtures/modules/ssh/files | 1 + spec/fixtures/modules/ssh/lib | 1 + spec/fixtures/modules/ssh/manifests | 1 + spec/fixtures/modules/ssh/templates | 1 + tests/server.pp | 1 + 12 files changed, 106 insertions(+) create mode 100644 .fixtures.yml create mode 100644 .gemfile create mode 100644 .travis.yml create mode 100644 Rakefile create mode 100644 manifests/site.pp create mode 100644 spec/classes/client_spec.rb create mode 100644 spec/classes/server_spec.rb create mode 120000 spec/fixtures/modules/ssh/files create mode 120000 spec/fixtures/modules/ssh/lib create mode 120000 spec/fixtures/modules/ssh/manifests create mode 120000 spec/fixtures/modules/ssh/templates create mode 100644 tests/server.pp diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 000000000..74ce67fb4 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,3 @@ +fixtures: + repositories: + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib" diff --git a/.gemfile b/.gemfile new file mode 100644 index 000000000..b17ef437b --- /dev/null +++ b/.gemfile @@ -0,0 +1,16 @@ +source 'https://rubygems.org' + +gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false + +if puppetversion = ENV['PUPPET_VERSION'] + gem 'puppet', puppetversion, :require => false + + if puppetversion[0].chr.to_i < 3 + gem 'hiera-puppet', :require => false + end + +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..ed76831d9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: ruby +rvm: + - 1.8.7 + - 1.9.3 +script: 'rake spec' +env: + - PUPPET_VERSION="~> 2.7.0" + - PUPPET_VERSION="3.3" +gemfile: .gemfile +branches: + only: + - master +notifications: + email: false diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..e47b27c58 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require 'rake' +require 'puppetlabs_spec_helper/rake_tasks' diff --git a/manifests/site.pp b/manifests/site.pp new file mode 100644 index 000000000..e69de29bb diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb new file mode 100644 index 000000000..cabe803d4 --- /dev/null +++ b/spec/classes/client_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'ssh::client', :type => 'class' do + context "On Debian with no other parameters" do + let :facts do + { + :osfamily => 'Debian', + :interfaces => 'eth0', + :ipaddress_eth0 => '192.168.1.1' + } + end + it { + should contain_package('openssh-client').with(:ensure => 'present') + } + end + context "On Debian with custom ensure" do + let :facts do + { + :osfamily => 'Debian', + :interfaces => 'eth0', + :ipaddress_eth0 => '192.168.1.1' + } + end + let :params do + { + :ensure => 'latest' + } + end + it { + should contain_package('openssh-client').with(:ensure => 'latest') + } + end +end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb new file mode 100644 index 000000000..fb0a16f04 --- /dev/null +++ b/spec/classes/server_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'ssh::server', :type => 'class' do + context "On Debian with no other parameters" do + let :facts do + { + :osfamily => 'Debian', + :interfaces => 'eth0', + :ipaddress_eth0 => '192.168.1.1' + } + end + it { + should contain_package('openssh-server').with(:ensure => 'present') + } + end + context "On Debian with custom ensure" do + let :facts do + { + :osfamily => 'Debian', + :interfaces => 'eth0', + :ipaddress_eth0 => '192.168.1.1' + } + end + let :params do + { + :ensure => 'latest' + } + end + it { + should contain_package('openssh-server').with(:ensure => 'latest') + } + end +end diff --git a/spec/fixtures/modules/ssh/files b/spec/fixtures/modules/ssh/files new file mode 120000 index 000000000..84dafe8de --- /dev/null +++ b/spec/fixtures/modules/ssh/files @@ -0,0 +1 @@ +../../../../files \ No newline at end of file diff --git a/spec/fixtures/modules/ssh/lib b/spec/fixtures/modules/ssh/lib new file mode 120000 index 000000000..42892ea04 --- /dev/null +++ b/spec/fixtures/modules/ssh/lib @@ -0,0 +1 @@ +../../../../lib \ No newline at end of file diff --git a/spec/fixtures/modules/ssh/manifests b/spec/fixtures/modules/ssh/manifests new file mode 120000 index 000000000..373b99206 --- /dev/null +++ b/spec/fixtures/modules/ssh/manifests @@ -0,0 +1 @@ +../../../../manifests \ No newline at end of file diff --git a/spec/fixtures/modules/ssh/templates b/spec/fixtures/modules/ssh/templates new file mode 120000 index 000000000..f8a06d1d1 --- /dev/null +++ b/spec/fixtures/modules/ssh/templates @@ -0,0 +1 @@ +../../../../templates \ No newline at end of file diff --git a/tests/server.pp b/tests/server.pp new file mode 100644 index 000000000..112640ec0 --- /dev/null +++ b/tests/server.pp @@ -0,0 +1 @@ +include ssh::server