From c36abdd9066175baa8b1da245fb563b1f2fabd58 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 14 Jul 2011 11:08:17 +0200 Subject: [PATCH] Adjust test, so that it runs on Windows --- test/fixtures/config-ldapdb.yaml | 4 ++-- test/test_pg_ldap_sync.rb | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/fixtures/config-ldapdb.yaml b/test/fixtures/config-ldapdb.yaml index 893df18..7dd6c28 100644 --- a/test/fixtures/config-ldapdb.yaml +++ b/test/fixtures/config-ldapdb.yaml @@ -16,9 +16,9 @@ ldap_groups: pg_connection: dbname: postgres + host: localhost + port: 54321 # needed for postgres-pr: -# host: localhost -# port: 54321 # user: insert_your_username_here # password: diff --git a/test/test_pg_ldap_sync.rb b/test/test_pg_ldap_sync.rb index b99f68c..4f41448 100644 --- a/test/test_pg_ldap_sync.rb +++ b/test/test_pg_ldap_sync.rb @@ -41,9 +41,9 @@ class TestPgLdapSync < Test::Unit::TestCase @port = 54321 ENV['PGPORT'] = @port.to_s ENV['PGHOST'] = 'localhost' - unless File.exist?('temp/pg_data') + unless File.exist?('temp/pg_data/PG_VERSION') FileUtils.mkdir_p 'temp/pg_data' - log_and_run 'initdb', '-D', 'temp/pg_data' + log_and_run 'initdb', '-D', 'temp/pg_data', '--no-locale' end log_and_run 'pg_ctl', '-w', '-o', "-k.", '-D', 'temp/pg_data', 'start' log_and_run 'psql', '-e', '-c', "DROP ROLE IF EXISTS fred, wilma, \"Flintstones\", \"Wilmas\", \"All Users\"", 'postgres' @@ -66,13 +66,22 @@ class TestPgLdapSync < Test::Unit::TestCase def psqlre(*args) /^\s*#{args[0]}[ |]*#{args[1]}[ |\{"]*#{args[2..-1].join('[", ]+')}["\}\s]*$/ end + + def exec_psql_du + text = if RUBY_PLATFORM=~/mingw|mswin/ + `psql -c \\du postgres` + else + `psql -c \\\\du postgres` + end + puts text + return text + end def test_sanity PgLdapSync::Application.run(%w[-c test/fixtures/config-ldapdb.yaml -vv]) ENV['LC_MESSAGES'] = 'C' - psql_du = `psql -c \\\\du postgres` - puts psql_du + psql_du = exec_psql_du assert_match(psqlre('All Users','Cannot login'), psql_du) assert_match(psqlre('Flintstones','Cannot login'), psql_du) @@ -84,8 +93,7 @@ class TestPgLdapSync < Test::Unit::TestCase @directory['cn=Flintstones,dc=example,dc=com']['member'].pop PgLdapSync::Application.run(%w[-c test/fixtures/config-ldapdb.yaml -vv]) - psql_du = `psql -c \\\\du postgres` - puts psql_du + psql_du = exec_psql_du assert_match(psqlre('All Users','Cannot login'), psql_du) assert_match(psqlre('Flintstones','Cannot login'), psql_du) @@ -99,8 +107,7 @@ class TestPgLdapSync < Test::Unit::TestCase @directory['cn=Flintstones,dc=example,dc=com']['member'] << 'cn=Wilma Flintstone,dc=example,dc=com' PgLdapSync::Application.run(%w[-c test/fixtures/config-ldapdb.yaml -vv]) - psql_du = `psql -c \\\\du postgres` - puts psql_du + psql_du = exec_psql_du assert_match(psqlre('All Users','Cannot login'), psql_du) assert_match(psqlre('Flintstones','Cannot login'), psql_du)