Permalink
Browse files

refactor for tests to use dynamically generated config files

  • Loading branch information...
1 parent 59bbea8 commit 518a692f4485fe924aaad4d9e9185e57e8b0fe3c @tardate tardate committed Sep 18, 2010
View
@@ -2,7 +2,7 @@
require 'mysql2psql/version'
require 'mysql2psql/config'
require 'mysql2psql/converter'
-require 'mysql2psql/mysqlreader'
+require 'mysql2psql/mysql_reader'
require 'mysql2psql/writer'
require 'mysql2psql/postgres_writer'
require 'mysql2psql/postgres_db_writer.rb'
@@ -14,7 +14,7 @@ class Mysql2psql
attr_reader :options, :reader, :writer
def initialize(args)
- help if args.length==1 && args[0] =~ /-.?|-*he?l?p?/i
+ help if args.length==1 && args[0] =~ /^-.?|^-*he?l?p?$/i
configfile = args[0] || File.expand_path('mysql2psql.yml')
@options = Config.new( configfile, true )
end
View
@@ -26,50 +26,75 @@ def reset_configfile(filepath)
end
file.close
end
-
- def self.template
- return <<EOS
+
+ def self.template(to_filename = nil, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false)
+ configtext = <<EOS
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
- username: somename
- password: secretpassword
- database: somename
+ username: mysql2psql
+ password:
+ database: mysql2psql_test
destination:
# if file is given, output goes to file, else postgres
- file:
+ file: #{ to_filename ? to_filename : ''}
postgres:
hostname: localhost
port: 5432
- username: somename
- password: secretpassword
- database: somename
+ username: mysql2psql
+ password:
+ database: mysql2psql_test
# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
+EOS
+ if include_tables.length>0
+ configtext += "\ntables:\n"
+ include_tables.each do |t|
+ configtext += "- #{t}\n"
+ end
+ end
+ configtext += <<EOS
+# if exclude_tables is given, exclude the listed tables from the conversion.
+#exclude_tables:
#- table3
#- table4
-# if exclude_tables is given, exclude the listed tables from the conversion.
-#exclude_tables:
-#- table5
-#- table6
+EOS
+ if exclude_tables.length>0
+ configtext += "\nexclude_tables:\n"
+ exclude_tables.each do |t|
+ configtext += "- #{t}\n"
+ end
+ end
+ if !supress_data.nil?
+ configtext += <<EOS
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-#supress_data: true
+supress_data: #{supress_data}
+EOS
+ end
+ if !supress_ddl.nil?
+ configtext += <<EOS
# if supress_ddl is true, only the data will be exported/imported, and not the schema
-#supress_ddl: false
+supress_ddl: #{supress_ddl}
+EOS
+ end
+ if !force_truncate.nil?
+ configtext += <<EOS
# if force_truncate is true, forces a table truncate before table loading
-#force_truncate: false
-
+force_truncate: #{force_truncate}
EOS
+ end
+ configtext
end
+
end
end
@@ -10,9 +10,9 @@ def initialize(reader, writer, options)
@options = options
@exclude_tables = options.exclude_tables([])
@only_tables = options.only_tables(nil)
- @supress_data = options.supress_data
- @supress_ddl = options.supress_ddl
- @force_truncate = options.force_truncate
+ @supress_data = options.supress_data(false)
+ @supress_ddl = options.supress_ddl(false)
+ @force_truncate = options.force_truncate(false)
end
def convert
File renamed without changes.
@@ -1,5 +1,7 @@
require 'pg'
+require 'mysql2psql/postgres_writer'
+
class Mysql2psql
class PostgresDbWriter < PostgresWriter
@@ -1,3 +1,5 @@
+require 'mysql2psql/postgres_writer'
+
class Mysql2psql
class PostgresFileWriter < PostgresWriter
@@ -1,5 +1,7 @@
require 'pg'
+require 'mysql2psql/writer'
+
class Mysql2psql
class PostgresWriter < Writer
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file:
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-#tables:
-#- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-#exclude_tables:
-#- table5
-#- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: false
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: false
-
-# if force_truncate is true, forces a table truncate before table loading
-#force_truncate: true
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file:
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-tables:
-- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-exclude_tables:
-- table5
-- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: true
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: true
-
-# if force_truncate is true, forces a table truncate before table loading
-force_truncate: true
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file: test/fixtures/test_output_convert_all.sql
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-#tables:
-#- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-#exclude_tables:
-#- table5
-#- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: false
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: false
-
-# if force_truncate is true, forces a table truncate before table loading
-#force_truncate: true
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file: test/fixtures/test_output_convert_nothing.sql
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-tables:
-- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-exclude_tables:
-- table5
-- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: true
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: true
-
-# if force_truncate is true, forces a table truncate before table loading
-force_truncate: true
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file: test/fixtures/test_output_convert_all.sql
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-#tables:
-#- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-#exclude_tables:
-#- table5
-#- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: false
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: true
-
-# if force_truncate is true, forces a table truncate before table loading
-force_truncate: true
@@ -1,35 +0,0 @@
-mysql:
- hostname: localhost
- port: 3306
- socket: /tmp/mysql.sock
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-destination:
- # if file is given, output goes to file, else postgres
- file: test/fixtures/test_output_convert_all.sql
- postgres:
- hostname: localhost
- port: 5432
- username: mysql2psql
- password:
- database: mysql2psql_test
-
-# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
-#tables:
-#- notexist
-
-# if exclude_tables is given, exclude the listed tables from the conversion.
-#exclude_tables:
-#- table5
-#- table6
-
-# if supress_data is true, only the schema definition will be exported/migrated, and not the data
-supress_data: true
-
-# if supress_ddl is true, only the data will be exported/imported, and not the schema
-supress_ddl: false
-
-# if force_truncate is true, forces a table truncate before table loading
-force_truncate: false
@@ -3,16 +3,18 @@
require 'mysql2psql'
class ConvertToDbTest < Test::Unit::TestCase
+
class << self
def startup
- configfile = "#{File.dirname(__FILE__)}/../fixtures/config_localmysql_to_db_convert_all.yml"
seed_test_database
- @@mysql2psql = Mysql2psql.new([configfile])
+ @@options=get_test_config_by_label(:localmysql_to_db_convert_all)
+ @@mysql2psql = Mysql2psql.new([@@options.filepath])
@@mysql2psql.convert
@@mysql2psql.writer.open
end
def shutdown
@@mysql2psql.writer.close
+ delete_files_for_test_config(@@options)
end
end
def setup
Oops, something went wrong.

0 comments on commit 518a692

Please sign in to comment.