spec_helper_system.rb 1.3 KB

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