pg_vm_context.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'logger'
  2. require 'vagrant'
  3. require 'support/postgres_test_config'
  4. if PostgresTestConfig::HardCoreTesting
  5. # this will just make sure that we throw an error if the user tries to
  6. # run w/o having Sahara installed
  7. require 'sahara'
  8. end
  9. shared_context :pg_vm_context do
  10. before(:all) do
  11. @logger = Logger.new(STDOUT)
  12. @logger.level = Logger::DEBUG # TODO: get from environment or rspec?
  13. @env = Vagrant::Environment::new(:cwd => vagrant_dir)
  14. if PostgresTestConfig::HardCoreTesting
  15. @env.cli("destroy", vm.to_s, "--force") # Takes too long
  16. end
  17. @env.cli("up", vm.to_s)
  18. if PostgresTestConfig::HardCoreTesting
  19. sudo_and_log(vm, 'if [ "$(facter osfamily)" == "Debian" ] ; then apt-get update ; fi')
  20. end
  21. install_postgres
  22. #sudo_and_log(vm, 'puppet apply -e "include postgresql::server"')
  23. if PostgresTestConfig::HardCoreTesting
  24. # Sahara ignores :cwd so we have to chdir for now, see https://github.com/jedi4ever/sahara/issues/9
  25. Dir.chdir(vagrant_dir)
  26. @env.cli("sandbox", "on", vm.to_s)
  27. end
  28. end
  29. after(:all) do
  30. if PostgresTestConfig::SuspendVMsAfterSuite
  31. @logger.debug("Suspending VM")
  32. @env.cli("suspend", vm.to_s)
  33. end
  34. end
  35. after(:each) do
  36. if PostgresTestConfig::HardCoreTesting
  37. @env.cli("sandbox", "rollback", vm.to_s)
  38. end
  39. end
  40. end