Files
metasploit-gs/lib/postgres_msf.rb.ut.rb
T
Tod Beardsley a65af9c8b3 See #730. Forking and adding Postgres-PR, with the following changes:
Namespaced everything under Msf::Db::PostgreSQL, renamed top-level include to postgres_msf to disambiguate.
Included recursive requires for all files.
Noted the IO monkeypatch -- should revisit.
Added a testcase for database connections.

The reason for the namespacing is to avoid stomping on any existing Postgres-PR installations, or any other requires named "postgres" or "postgresql" or even "pg," since these may or may not support the method's we're using here. The seperate namespace also allows for easier integration of custom commands later on.




git-svn-id: file:///home/svn/framework3/trunk@8342 4d416f70-5f16-0410-b530-b9f4589650da
2010-02-01 19:49:36 +00:00

54 lines
1.6 KiB
Ruby

#!/usr/bin/env ruby
require 'test/unit'
require 'postgres_msf'
$_POSTGRESQL_TEST_SERVERNAME = 'dbsrv' # Name or IP, default: dbsrv
$_POSTGRESQL_TEST_SERVERPORT = 5432 # Default: 5432
$_POSTGRESQL_TEST_DATABASE = 'mydb' # Default: mydb
$_POSTGRESQL_TEST_USERNAME = 'scott' # Default: scott
$_POSTGRESQL_TEST_PASSWORD = 'tiger' # Default: tiger
class Msf::Db::PostgresPR::UnitTest < ::Test::Unit::TestCase
def test_connection
srv = "tcp://#{$_POSTGRESQL_TEST_SERVERNAME}:#{$_POSTGRESQL_TEST_SERVERPORT}"
conn = Msf::Db::PostgresPR::Connection.new($_POSTGRESQL_TEST_DATABASE,
$_POSTGRESQL_TEST_USERNAME,
$_POSTGRESQL_TEST_PASSWORD,
srv)
assert_kind_of Msf::Db::PostgresPR::Connection, conn
assert_nothing_raised { conn.close }
end
# Note that this will drop the "test" table for the named database.
# This is a destructive act!
def test_query
srv = "tcp://#{$_POSTGRESQL_TEST_SERVERNAME}:#{$_POSTGRESQL_TEST_SERVERPORT}"
conn = Msf::Db::PostgresPR::Connection.new($_POSTGRESQL_TEST_DATABASE,
$_POSTGRESQL_TEST_USERNAME,
$_POSTGRESQL_TEST_PASSWORD,
srv)
begin
conn.query("drop table test")
rescue RuntimeError # Cleanup, it may or may not be there.
end
assert_nothing_raised do
conn.query("CREATE TABLE test (i int, v varchar(5))")
conn.query(%q{INSERT INTO test VALUES (1, 'foo')})
conn.query(%q{INSERT INTO test VALUES (2, 'bar')})
end
resp = conn.query("select * from test")
assert_equal(2, resp.rows.size)
assert_equal(2, resp.fields.size)
assert_equal("SELECT", resp.cmd_tag)
assert_nothing_raised { conn.query("drop table test") }
end
end