Framework for testing on Cent6 / PG9
This commit does the following: * Adds a CentOS6 vm to the Vagrantfile * Reorganizes the spec test file a bit so that it will be easy to test various things on different VMs. This is in preparation for adding some PG9 tests to run on Cent6.
This commit is contained in:
parent
5585b6bb50
commit
bdecbe6503
2 changed files with 169 additions and 105 deletions
13
spec/Vagrantfile
vendored
13
spec/Vagrantfile
vendored
|
@ -21,9 +21,16 @@
|
|||
|
||||
Vagrant::Config.run do |config|
|
||||
|
||||
# Test on 64 bit lucid
|
||||
config.vm.box = "lucid64"
|
||||
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
|
||||
config.vm.define :lucid do |lucid_config|
|
||||
# Test on 64 bit lucid
|
||||
lucid_config.vm.box = "lucid64"
|
||||
lucid_config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
|
||||
end
|
||||
|
||||
config.vm.define :cent6 do |cent_config|
|
||||
cent_config.vm.box = "cent63_64"
|
||||
cent_config.vm.box_url = "https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box"
|
||||
end
|
||||
|
||||
# Resolve DNS via NAT
|
||||
config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
|
||||
|
|
|
@ -30,10 +30,25 @@ require 'vagrant'
|
|||
|
||||
describe "postgresql" do
|
||||
|
||||
def sudo_and_log(*args)
|
||||
@logger.debug("Running command: '#{args[0]}'")
|
||||
# Tests are pretty slow w/sahara, and when we destroy the VMs at the beginning
|
||||
# of the test run. This can be a hindrance for development but is very
|
||||
# valuable for final testing. This constant allows you to toggle between
|
||||
# strict testing and less strict testing--the latter being useful for
|
||||
# development purposes.
|
||||
HardCoreTesting = false
|
||||
|
||||
|
||||
if HardCoreTesting
|
||||
# this will just make sure that we throw an error if the user tries to
|
||||
# run w/o having Sahara installed
|
||||
require 'sahara'
|
||||
end
|
||||
|
||||
|
||||
def sudo_and_log(vm, cmd)
|
||||
@logger.debug("Running command: '#{cmd}'")
|
||||
result = ""
|
||||
@env.primary_vm.channel.sudo(args[0]) do |ch, data|
|
||||
@env.vms[vm].channel.sudo(cmd) do |ch, data|
|
||||
result << data
|
||||
@logger.debug(data)
|
||||
end
|
||||
|
@ -49,124 +64,166 @@ describe "postgresql" do
|
|||
|
||||
# Sahara ignores :cwd so we have to chdir for now, see https://github.com/jedi4ever/sahara/issues/9
|
||||
Dir.chdir(vagrant_dir)
|
||||
|
||||
@env.cli("destroy --force") # Takes too long
|
||||
@env.cli("up")
|
||||
|
||||
# We are not testing the "package" resource type, so pull stuff in in advance
|
||||
sudo_and_log('apt-get update')
|
||||
sudo_and_log('apt-get install --yes --download-only postgresql-8.4')
|
||||
@env.cli("sandbox", "on")
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@env.cli("sandbox", "rollback")
|
||||
end
|
||||
|
||||
describe 'postgresql::initdb' do
|
||||
it "should idempotently create a working --pgdata directory so postgres can run" do
|
||||
@logger.info("starting")
|
||||
basic_testing_vms = [:lucid]
|
||||
|
||||
# A bare-minimum class to initdb the specified dir
|
||||
test_class = 'class {"postgresql_tests::test_initdb": }'
|
||||
|
||||
# Run once to check for crashes
|
||||
sudo_and_log("puppet apply -e '#{test_class}'")
|
||||
basic_testing_vms.each do |vm|
|
||||
describe "basic (system default postgres) tests (vm: #{vm})" do
|
||||
before (:all) do
|
||||
if HardCoreTesting
|
||||
@env.cli("destroy", vm.to_s, "--force") # Takes too long
|
||||
end
|
||||
@env.cli("up", vm.to_s)
|
||||
|
||||
# Run again to check for idempotence via --detailed-exitcodes
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
# We are not testing the "package" resource type, so pull stuff in in advance
|
||||
sudo_and_log(vm, 'apt-get update')
|
||||
sudo_and_log(vm, 'apt-get install --yes --download-only postgresql-8.4')
|
||||
if HardCoreTesting
|
||||
@env.cli("sandbox", "on", vm.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
sudo_and_log("service postgresql-8.4 restart")
|
||||
after(:each) do
|
||||
if HardCoreTesting
|
||||
@env.cli("sandbox", "rollback", vm.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
# Connect to it and list the databases
|
||||
sudo_and_log('sudo -n -u postgres /usr/lib/postgresql/8.4/bin/psql --list --tuples-only')
|
||||
end
|
||||
end
|
||||
describe 'postgresql::initdb' do
|
||||
it "should idempotently create a working --pgdata directory so postgres can run" do
|
||||
@logger.info("starting")
|
||||
|
||||
describe 'postgresql::db' do
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
|
||||
# A bare-minimum class to add a DB to postgres, which will be running due to ubuntu
|
||||
test_class = 'class {"postgresql_tests::test_db": db => "postgresql_test_db" }'
|
||||
# A bare-minimum class to initdb the specified dir
|
||||
test_class = 'class {"postgresql_tests::test_initdb": }'
|
||||
|
||||
begin
|
||||
# Run once to check for crashes
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'; [ $? == 2 ]")
|
||||
# Run once to check for crashes
|
||||
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
# Run again to check for idempotence via --detailed-exitcodes
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the database name is present
|
||||
sudo_and_log('sudo -u postgres psql postgresql_test_db --command="select datname from pg_database limit 1"')
|
||||
ensure
|
||||
sudo_and_log('sudo -u postgres psql --command="drop database postgresql_test_db" postgres')
|
||||
sudo_and_log(vm, "service postgresql-8.4 restart")
|
||||
|
||||
# Connect to it and list the databases
|
||||
sudo_and_log(vm, 'sudo -n -u postgres /usr/lib/postgresql/8.4/bin/psql --list --tuples-only')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql::db' do
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
|
||||
# A bare-minimum class to add a DB to postgres, which will be running due to ubuntu
|
||||
test_class = 'class {"postgresql_tests::test_db": db => "postgresql_test_db" }'
|
||||
|
||||
begin
|
||||
# Run once to check for crashes
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'; [ $? == 2 ]")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the database name is present
|
||||
sudo_and_log(vm, 'sudo -u postgres psql postgresql_test_db --command="select datname from pg_database limit 1"')
|
||||
ensure
|
||||
sudo_and_log(vm, 'sudo -u postgres psql --command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql::psql' do
|
||||
it 'should emit a deprecation warning' do
|
||||
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1" }'
|
||||
|
||||
data = sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'; [ $? == 2 ]")
|
||||
|
||||
data.should match /postgresql::psql is deprecated/
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql_psql' do
|
||||
it 'should run some SQL when the unless query returns no rows' do
|
||||
test_class = 'class {"postgresql_tests::test_ruby_psql": command => "SELECT 1", unless => "SELECT 1 WHERE 1=2" }'
|
||||
|
||||
# Run once to get all packages set up
|
||||
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
|
||||
|
||||
# Check for exit code 2
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}' ; [ $? == 2 ]")
|
||||
end
|
||||
|
||||
it 'should not run SQL when the unless query returns rows' do
|
||||
test_class = 'class {"postgresql_tests::test_ruby_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1" }'
|
||||
|
||||
# Run once to get all packages set up
|
||||
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
|
||||
|
||||
# Check for exit code 0
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'postgresql::user' do
|
||||
it 'should idempotently create a user who can log in' do
|
||||
test_class = 'class {"postgresql_tests::test_user": user => "postgresql_test_user", password => "postgresql_test_password" }'
|
||||
|
||||
# Run once to check for crashes
|
||||
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the user can log in
|
||||
sudo_and_log(vm, 'sudo -u postgresql_test_user psql --command="select datname from pg_database limit 1" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql::grant' do
|
||||
it 'should grant access so a user can create in a database' do
|
||||
test_class = 'class {"postgresql_tests::test_grant_create": db => "postgres", user => "psql_grant_tester", password => "psql_grant_pw" }'
|
||||
|
||||
# Run once to check for crashes
|
||||
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
sudo_and_log(vm, 'sudo -u psql_grant_tester psql --command="create table foo (foo int)" postgres')
|
||||
|
||||
sudo_and_log(vm, 'sudo -u psql_grant_tester psql --command="drop table foo" postgres')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql::psql' do
|
||||
it 'should emit a deprecation warning' do
|
||||
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1" }'
|
||||
non_default_testing_vms = [:cent6]
|
||||
|
||||
data = sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'; [ $? == 2 ]")
|
||||
non_default_testing_vms.each do |vm|
|
||||
describe "non-system-default postgres version tests (vm: #{vm})" do
|
||||
before (:all) do
|
||||
if HardCoreTesting
|
||||
@env.cli("destroy", vm.to_s, "--force") # Takes too long
|
||||
end
|
||||
@env.cli("up", vm.to_s)
|
||||
|
||||
data.should match /postgresql::psql is deprecated/
|
||||
if HardCoreTesting
|
||||
@env.cli("sandbox", "on", vm.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
after(:each) do
|
||||
if HardCoreTesting
|
||||
@env.cli("sandbox", "rollback", vm.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql_psql' do
|
||||
it 'should run some SQL when the unless query returns no rows' do
|
||||
test_class = 'class {"postgresql_tests::test_ruby_psql": command => "SELECT 1", unless => "SELECT 1 WHERE 1=2" }'
|
||||
|
||||
# Run once to get all packages set up
|
||||
sudo_and_log("puppet apply -e '#{test_class}'")
|
||||
|
||||
# Check for exit code 2
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}' ; [ $? == 2 ]")
|
||||
end
|
||||
|
||||
it 'should not run SQL when the unless query returns rows' do
|
||||
test_class = 'class {"postgresql_tests::test_ruby_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1" }'
|
||||
|
||||
# Run once to get all packages set up
|
||||
sudo_and_log("puppet apply -e '#{test_class}'")
|
||||
|
||||
# Check for exit code 0
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'postgresql::user' do
|
||||
it 'should idempotently create a user who can log in' do
|
||||
test_class = 'class {"postgresql_tests::test_user": user => "postgresql_test_user", password => "postgresql_test_password" }'
|
||||
|
||||
# Run once to check for crashes
|
||||
sudo_and_log("puppet apply -e '#{test_class}'")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the user can log in
|
||||
sudo_and_log('sudo -u postgresql_test_user psql --command="select datname from pg_database limit 1" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'postgresql::grant' do
|
||||
it 'should grant access so a user can create in a database' do
|
||||
test_class = 'class {"postgresql_tests::test_grant_create": db => "postgres", user => "psql_grant_tester", password => "psql_grant_pw" }'
|
||||
|
||||
# Run once to check for crashes
|
||||
sudo_and_log("puppet apply -e '#{test_class}'")
|
||||
|
||||
# Run again to check for idempotence
|
||||
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
sudo_and_log('sudo -u psql_grant_tester psql --command="create table foo (foo int)" postgres')
|
||||
|
||||
sudo_and_log('sudo -u psql_grant_tester psql --command="drop table foo" postgres')
|
||||
it "should have the echo command" do
|
||||
sudo_and_log(vm, 'echo "hi"')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue