Commits

Paul Gallagher  committed 6702232

refactor integration tests for suite-level setup

  • Participants
  • Parent commits bab2036

Comments (0)

Files changed (5)

     gem.authors = ["Paul Gallagher"]
     gem.add_dependency "mysql", "= 2.8.1"
     gem.add_dependency "pg", "= 0.9.0"
+    gem.add_development_dependency "test-unit", ">= 2.1.1"
     # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
   end
   Jeweler::GemcutterTasks.new
 
 require 'rake/testtask'
 namespace :test do
-
   Rake::TestTask.new(:units) do |test|
     test.libs << 'lib' << 'test/lib'
     test.pattern = 'test/units/*test.rb'

File test/integration/convert_to_db_test.rb

 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])
+      @@mysql2psql.convert
+    end
+    def shutdown
+    end
+  end
   def setup
-    seed_test_database
-
   end
   def teardown
-
   end
 
 

File test/integration/convert_to_file_test.rb

 require 'mysql2psql'
 
 class ConvertToFileTest < Test::Unit::TestCase
-  attr_reader :configfile, :mysql2psql
+  
+  class << self
+    def startup
+      configfile = "#{File.dirname(__FILE__)}/../fixtures/config_localmysql_to_file_convert_all.yml"
+      seed_test_database
+      @@mysql2psql = Mysql2psql.new([configfile])
+      @@mysql2psql.convert
+      @@content = IO.read(@@mysql2psql.options.destfile)
+    end
+    def shutdown
+      File.delete(@@mysql2psql.options.destfile) if File.exists?(@@mysql2psql.options.destfile)
+    end
+  end
   def setup
-    seed_test_database
-    @configfile = "#{File.dirname(__FILE__)}/../fixtures/config_localmysql_to_file_convert_all.yml"
-    @mysql2psql = Mysql2psql.new([configfile])
-    mysql2psql.convert
   end
   def teardown
-    File.delete(mysql2psql.options.destfile) if File.exists?(mysql2psql.options.destfile)
   end
-  def test_convert
-    #assert_equal 0,mysql2psql
+  def content
+    @@content
+  end
+  
+  def test_table_creation
+    assert_not_nil content.match('DROP TABLE IF EXISTS "numeric_types_basics" CASCADE')
+    assert_not_nil content.match(/CREATE TABLE "numeric_types_basics"/)
+  end
+
+  def test_basic_numerics_tinyint
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_tinyint" smallint,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_smallint
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_smallint" integer,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_mediumint
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_mediumint" integer,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_int
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_int" integer,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_integer
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_integer" integer,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_bigint
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_bigint" bigint,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_real
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_real" double precision,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_double
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_double" double precision,.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_float
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_float" numeric\(20, 0\),.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_decimal
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_decimal" numeric\(10, 0\),.*\)', Regexp::MULTILINE).match( content )
+  end
+  def test_basic_numerics_numeric
+    assert_not_nil Regexp.new('CREATE TABLE "numeric_types_basics".*"f_numeric" numeric\(10, 0\)[\w\n]*\)', Regexp::MULTILINE).match( content )
   end
 
 end

File test/lib/test_helper.rb

   raise StandardError.new("Failed to initialize converter from #{options.inspect}. See README for setup requirements.")
 end
 
-def file_contains(filepath,regex)
-  rc=false
-  File.foreach(filepath) do |line|
-    rc = rc || ( line =~ /#{regex}/ ) != nil
-  end
-  rc
-end
-
 def get_temp_file(basename)
   require 'tempfile'
   f = Tempfile.new(basename)

File test/units/postgres_file_writer_test.rb

 require 'mysql2psql'
 
 class PostgresFileWriterTest < Test::Unit::TestCase
-  attr_accessor :options
+  attr_accessor :destfile
   def setup
     begin
       f = Tempfile.new('mysql2psql_test_destfile')
     end
   end
   def teardown
-    File.delete(@destfile) if File.exists?(@destfile)
+    File.delete(destfile) if File.exists?(destfile)
   end
   
   def test_basic_write
-    writer = Mysql2psql::PostgresFileWriter.new(@destfile)
+    writer = Mysql2psql::PostgresFileWriter.new(destfile)
     writer.close
-    assert_true file_contains(@destfile, "SET client_encoding = 'UTF8'")
-    assert_false file_contains(@destfile, "unobtanium")
+    content = IO.read(destfile)
+    assert_not_nil content.match("SET client_encoding = 'UTF8'")
+    assert_nil content.match("unobtanium")
   end