From 5ef2f9dd23b952c625a59f48785f8ee82916d41b Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Nov 2015 15:14:00 +0100 Subject: ensure couchrest is not too new the latest version of couchrest depends on mime-types which depends on ruby 2.0 --- manifests/base.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/base.pp b/manifests/base.pp index 1ea41d1..7413c42 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -32,9 +32,15 @@ class couchdb::base { # and it needs the ruby-dev package installed to build #include ruby::devel + case $::operatingsystemmajrelease { + '7': { $couchrest_version = '1.2'} + default:{ $couchrest_version = 'latest'} + } + ensure_packages('ruby-dev') ensure_packages('couchrest', { provider => 'gem', + ensure => $couchrest_version, require => Package['ruby-dev'] }) -- cgit v1.2.3 From 2ac3b7c2e3283e5b0f48e6dd3d76c0192ee96a44 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 24 Nov 2015 17:15:12 +0100 Subject: test if couchrest gets installed with the correct version the old unit tests were not working anymore --- .fixtures.yml | 6 ++ Rakefile | 19 +++++ spec/classes/couchdb_spec.rb | 35 +++++++++ spec/fixtures/manifests/site.pp | 8 ++ spec/spec_helper.rb | 9 +++ spec/unit/data/map+reduce.txt | 3 - spec/unit/data/map.txt | 4 - spec/unit/data/missing.txt | 1 - spec/unit/data/one-document.txt | 1 - spec/unit/data/proxy-failure.txt | 1 - .../puppet/parser/functions/couchdblookup_spec.rb | 89 ---------------------- 11 files changed, 77 insertions(+), 99 deletions(-) create mode 100644 .fixtures.yml create mode 100644 Rakefile create mode 100644 spec/classes/couchdb_spec.rb create mode 100644 spec/fixtures/manifests/site.pp create mode 100644 spec/spec_helper.rb delete mode 100644 spec/unit/data/map+reduce.txt delete mode 100644 spec/unit/data/map.txt delete mode 100644 spec/unit/data/missing.txt delete mode 100644 spec/unit/data/one-document.txt delete mode 100644 spec/unit/data/proxy-failure.txt delete mode 100755 spec/unit/puppet/parser/functions/couchdblookup_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..50c6c9a --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,6 @@ +fixtures: + symlinks: + couchdb: "#{source_dir}" + repositories: + stdlib: " https://leap.se/git/puppet_stdlib" + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..85326bb --- /dev/null +++ b/Rakefile @@ -0,0 +1,19 @@ +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 + +task :test => [:lint, :syntax , :validate, :spec] diff --git a/spec/classes/couchdb_spec.rb b/spec/classes/couchdb_spec.rb new file mode 100644 index 0000000..0dd069a --- /dev/null +++ b/spec/classes/couchdb_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'couchdb' do + context 'given it is a wheezy system' do + let(:params) { {:admin_pw => 'foo'} } + let(:facts) do + { + :operatingsystemmajrelease => '7', + :operatingsystem => 'Debian', + :lsbdistcodename => 'wheezy', + } + end + it "should install couchrest 1.2" do + should contain_package('couchrest').with({ + 'ensure'=> '1.2', + }) + end + end + context 'given it is a jessie system' do + let(:params) { {:admin_pw => 'foo'} } + let(:facts) do + { + :operatingsystemmajrelease => '8', + :operatingsystem => 'Debian', + :lsbdistcodename => 'jessie', + } + end + it "should install latest couchrest version" do + should contain_package('couchrest').with({ + 'ensure'=> 'latest', + }) + end + end +end + diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 0000000..a959fb7 --- /dev/null +++ b/spec/fixtures/manifests/site.pp @@ -0,0 +1,8 @@ +# set a default exec path +# the logoutput exec parameter defaults to "on_error" in puppet 3, +# but to "false" in puppet 2.7, so we need to set this globally here +Exec { + logoutput => on_failure, + path => '/usr/bin:/usr/sbin/:/bin:/sbin:/usr/local/bin:/usr/local/sbin' +} + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b55ede8 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +require 'rspec-puppet' + +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) + +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + c.environmentpath = File.join(Dir.pwd, 'spec') +end diff --git a/spec/unit/data/map+reduce.txt b/spec/unit/data/map+reduce.txt deleted file mode 100644 index 71e1836..0000000 --- a/spec/unit/data/map+reduce.txt +++ /dev/null @@ -1,3 +0,0 @@ -{"rows":[ -{"key":1,"value":["foo","bar","baz"]} -]} diff --git a/spec/unit/data/map.txt b/spec/unit/data/map.txt deleted file mode 100644 index 4335913..0000000 --- a/spec/unit/data/map.txt +++ /dev/null @@ -1,4 +0,0 @@ -{"total_rows":2,"offset":0,"rows":[ -{"id":"foo","key":1,"value":"foo"}, -{"id":"bar","key":2,"value":"bar"} -]} diff --git a/spec/unit/data/missing.txt b/spec/unit/data/missing.txt deleted file mode 100644 index 4e6d97e..0000000 --- a/spec/unit/data/missing.txt +++ /dev/null @@ -1 +0,0 @@ -{"error":"not_found","reason":"missing"} diff --git a/spec/unit/data/one-document.txt b/spec/unit/data/one-document.txt deleted file mode 100644 index 071cd7e..0000000 --- a/spec/unit/data/one-document.txt +++ /dev/null @@ -1 +0,0 @@ -{"_id":"foobar","_rev":"1-1750d8614a19943f36b545e7c5549503","wiki":true,"rt":true,"svn":true,"dav":null} diff --git a/spec/unit/data/proxy-failure.txt b/spec/unit/data/proxy-failure.txt deleted file mode 100644 index f5f1c37..0000000 --- a/spec/unit/data/proxy-failure.txt +++ /dev/null @@ -1 +0,0 @@ -

It works!

diff --git a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb deleted file mode 100755 index 8777d71..0000000 --- a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env rspec - -require 'puppet' - -describe "the couchdblookup function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - @datapath = File.dirname(__FILE__) + '/../../../data/' - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("couchdblookup").should == "function_couchdblookup" - end - - it "should raise a ParseError unless there is exactly 2 arguments" do - lambda { @scope.function_couchdblookup([]) }.should raise_error(Puppet::ParseError) - lambda { @scope.function_couchdblookup([1]) }.should raise_error(Puppet::ParseError) - lambda { @scope.function_couchdblookup([1,2,3]) }.should raise_error(Puppet::ParseError) - end - - it "should return the value of a key from a single couchdb document" do - sample_json = File.open(@datapath + 'one-document.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = @scope.function_couchdblookup(["http://fake/uri", "wiki"]) - result.should eq(true) - end - - it "should raise a ParseError if a key can't be found in a couchdb document" do - sample_json = File.open(@datapath + 'one-document.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = lambda { @scope.function_couchdblookup(["http://fake/uri", "fake-key"]) } - result.should raise_error(Puppet::ParseError) - end - - it "should return an array from the values of a couchdb view" do - sample_json = File.open(@datapath + 'map.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = @scope.function_couchdblookup(["http://fake/uri", "value"]) - result.should eq(["foo", "bar"]) - end - - it "should raise a ParseError if a key can't be found in the rows of a couchdb view" do - sample_json = File.open(@datapath + 'map.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = lambda { @scope.function_couchdblookup(["http://fake/uri", "fake-key"]) } - result.should raise_error(Puppet::ParseError) - end - - it "should return an array the values from a couchdb reduced view" do - sample_json = File.open(@datapath + 'map+reduce.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = @scope.function_couchdblookup(["http://fake/uri", "value"]) - result.should eq(["foo", "bar", "baz"]) - end - - it "should raise a ParseError if a key can't be found in the rows of a couchdb reduced view" do - sample_json = File.open(@datapath + 'map+reduce.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = lambda { @scope.function_couchdblookup(["http://fake/uri", "fake-key"]) } - result.should raise_error(Puppet::ParseError) - end - - it "should raise a ParseError if couchdb can't find the requested document" do - sample_json = File.open(@datapath + 'missing.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = lambda { @scope.function_couchdblookup(["http://fake/uri", "a-key"]) } - result.should raise_error(Puppet::ParseError) - end - - it "should raise a ParseError if input in not valid JSON" do - sample_json = File.open(@datapath + 'proxy-failure.txt') - OpenURI.stub!(:open_uri).and_return(sample_json) - - result = lambda { @scope.function_couchdblookup(["http://fake/uri", "a-key"]) } - result.should raise_error(Puppet::ParseError) - end - -end -- cgit v1.2.3