7fdb9e30c2c259ffe12543b40191e5763df1e530
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / spec_helper_system.rb
1 require 'rspec-system/spec_helper'
2 require 'rspec-system-puppet/helpers'
3 require 'tempfile'
4
5 module LocalHelpers
6   include RSpecSystem::Util
7
8   def psql(psql_cmd, user = 'postgres', &block)
9     psql = "psql #{psql_cmd}"
10     shell("su #{shellescape(user)} -c #{shellescape(psql)}", &block)
11   end
12 end
13
14 include RSpecSystemPuppet::Helpers
15
16 RSpec.configure do |c|
17   # Project root for the firewall code
18   proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
19
20   # Enable colour in Jenkins
21   c.tty = true
22
23   # Include in our local helpers
24   c.include ::LocalHelpers
25
26   # Puppet helpers
27   c.include RSpecSystemPuppet::Helpers
28   c.extend RSpecSystemPuppet::Helpers
29
30   # This is where we 'setup' the nodes before running our tests
31   c.before :suite do
32     # Install puppet
33     puppet_install
34
35     # Copy this module into the module path of the test node
36     puppet_module_install(:source => proj_root, :module_name => 'postgresql')
37     shell('puppet module install puppetlabs/stdlib')
38     shell('puppet module install puppetlabs/firewall')
39     shell('puppet module install puppetlabs/apt')
40     shell('puppet module install ripienaar/concat')
41
42     file = Tempfile.new('foo')
43     begin
44       file.write(<<-EOS)
45 ---
46 :logger: noop
47       EOS
48       file.close
49       rcp(:sp => file.path, :dp => '/etc/puppet/hiera.yaml')
50     ensure
51       file.unlink
52     end
53   end
54 end