Best Minitest_ruby code snippet using MyModule.name
test_runtime_basic.rb
Source:test_runtime_basic.rb
...120 mock = Dbt::DbDriver.new121 Dbt.runtime.instance_variable_set('@db', mock)122 config = create_postgres_config()123 db_scripts = create_dir('databases')124 module_name = 'MyModule'125 table_names = %w([MyModule].[foo] [MyModule].[bar] [MyModule].[baz])126 database = create_simple_db_definition(db_scripts, module_name, table_names)127 sql = 'SELECT 42'128 mock.expects(:open).with(config, false).in_sequence(@s)129 mock.expects(:query).with(sql).in_sequence(@s)130 mock.expects(:close).with().in_sequence(@s)131 Dbt.runtime.query(database, sql)132 end133 def test_create134 mock = Dbt::DbDriver.new135 Dbt.runtime.instance_variable_set('@db', mock)136 config = create_postgres_config()137 db_scripts = create_dir('databases')138 module_name = 'MyModule'139 table_names = %w([MyModule].[foo] [MyModule].[bar] [MyModule].[baz])140 database = create_simple_db_definition(db_scripts, module_name, table_names)141 mock.expects(:open).with(config, true).in_sequence(@s)142 mock.expects(:drop).with(database, config).in_sequence(@s)143 mock.expects(:create_database).with(database, config).in_sequence(@s)144 mock.expects(:close).with().in_sequence(@s)145 mock.expects(:open).with(config, false).in_sequence(@s)146 mock.expects(:create_schema).with(module_name).in_sequence(@s)147 mock.expects(:close).with().in_sequence(@s)148 Dbt.runtime.create(database)149 end150 def test_create_by_import151 mock = Dbt::DbDriver.new152 Dbt.runtime.instance_variable_set('@db', mock)153 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))154 db_scripts = create_dir('databases')155 module_name = 'MyModule'156 table_names = %w([MyModule].[foo])157 database = create_simple_db_definition(db_scripts, module_name, table_names)158 database.separate_import_task = true159 import = database.add_import(:default, {})160 mock.expects(:open).with(config, true).in_sequence(@s)161 mock.expects(:drop).with(database, config).in_sequence(@s)162 mock.expects(:create_database).with(database, config).in_sequence(@s)163 mock.expects(:close).with().in_sequence(@s)164 mock.expects(:open).with(config, false).in_sequence(@s)165 mock.expects(:create_schema).with(module_name).in_sequence(@s)166 expect_default_table_import(mock, import, module_name, 'foo')167 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)168 mock.expects(:post_database_import).with(import).in_sequence(@s)169 mock.expects(:close).with().in_sequence(@s)170 Dbt.runtime.create_by_import(import)171 end172 def test_create_with_no_create173 mock = Dbt::DbDriver.new174 Dbt.runtime.instance_variable_set('@db', mock)175 config = create_postgres_config('no_create' => true)176 db_scripts = create_dir('databases')177 module_name = 'MyModule'178 table_names = %w([MyModule].[foo] [MyModule].[bar] [MyModule].[baz])179 database = create_simple_db_definition(db_scripts, module_name, table_names)180 mock.expects(:open).with(config, false).in_sequence(@s)181 mock.expects(:create_schema).with(module_name).in_sequence(@s)182 mock.expects(:close).with().in_sequence(@s)183 Dbt.runtime.create(database)184 end185 def test_create_with_multiple_fixtures186 mock = Dbt::DbDriver.new187 Dbt.runtime.instance_variable_set('@db', mock)188 config = create_postgres_config()189 db_scripts = create_dir('databases')190 module_name = 'MyModule'191 table_names = %w([MyModule].[foo] [MyModule].[bar])192 database = create_simple_db_definition(db_scripts, module_name, table_names)193 create_fixture(module_name, 'foo')194 create_fixture(module_name, 'bar')195 mock.expects(:open).with(config, true).in_sequence(@s)196 mock.expects(:drop).with(database, config).in_sequence(@s)197 mock.expects(:create_database).with(database, config).in_sequence(@s)198 mock.expects(:close).with().in_sequence(@s)199 mock.expects(:open).with(config, false).in_sequence(@s)200 mock.expects(:create_schema).with(module_name).in_sequence(@s)201 expect_delete(mock, module_name, 'bar')202 expect_delete(mock, module_name, 'foo')203 expect_fixture(mock, module_name, 'foo')204 expect_fixture(mock, module_name, 'bar')205 mock.expects(:close).with().in_sequence(@s)206 Dbt.runtime.create(database)207 end208 def test_create_with_unexpected_fixtures209 mock = Dbt::DbDriver.new210 Dbt.runtime.instance_variable_set('@db', mock)211 config = create_postgres_config()212 db_scripts = create_dir('databases')213 module_name = 'MyModule'214 table_names = %w([MyModule].[foo] [MyModule].[bar])215 database = create_simple_db_definition(db_scripts, module_name, table_names)216 create_fixture(module_name, 'baz')217 mock.expects(:open).with(config, true).in_sequence(@s)218 mock.expects(:drop).with(database, config).in_sequence(@s)219 mock.expects(:create_database).with(database, config).in_sequence(@s)220 mock.expects(:close).with().in_sequence(@s)221 mock.expects(:open).with(config, false).in_sequence(@s)222 mock.expects(:create_schema).with(module_name).in_sequence(@s)223 mock.expects(:close).with().in_sequence(@s)224 assert_raises(RuntimeError) do225 Dbt.runtime.create(database)226 end227 end228 def test_create_with_fixtures229 mock = Dbt::DbDriver.new230 Dbt.runtime.instance_variable_set('@db', mock)231 config = create_postgres_config()232 db_scripts = create_dir('databases')233 module_name = 'MyModule'234 table_names = %w([MyModule].[foo] [MyModule].[bar])235 database = create_simple_db_definition(db_scripts, module_name, table_names)236 create_fixture(module_name, 'foo')237 mock.expects(:open).with(config, true).in_sequence(@s)238 mock.expects(:drop).with(database, config).in_sequence(@s)239 mock.expects(:create_database).with(database, config).in_sequence(@s)240 mock.expects(:close).with().in_sequence(@s)241 mock.expects(:open).with(config, false).in_sequence(@s)242 mock.expects(:create_schema).with(module_name).in_sequence(@s)243 expect_delete(mock, module_name, 'foo')244 expect_fixture(mock, module_name, 'foo')245 mock.expects(:close).with().in_sequence(@s)246 Dbt.runtime.create(database)247 end248 def test_create_with_fixtures_including_non_fixture249 mock = Dbt::DbDriver.new250 Dbt.runtime.instance_variable_set('@db', mock)251 config = create_postgres_config()252 db_scripts = create_dir('databases')253 module_name = 'MyModule'254 table_names = ['[foo]', '[bar]']255 database = create_simple_db_definition(db_scripts, module_name, table_names)256 create_file("databases/#{module_name}/fixtures/bar.sql", 'SELECT * FROM tblNotRun')257 mock.expects(:open).with(config, true).in_sequence(@s)258 mock.expects(:drop).with(database, config).in_sequence(@s)259 mock.expects(:create_database).with(database, config).in_sequence(@s)260 mock.expects(:close).with().in_sequence(@s)261 mock.expects(:open).with(config, false).in_sequence(@s)262 mock.expects(:create_schema).with(module_name).in_sequence(@s)263 mock.expects(:close).with().in_sequence(@s)264 assert_raises(RuntimeError) do265 Dbt.runtime.create(database)266 end267 end268 def test_create_with_sql269 mock = Dbt::DbDriver.new270 Dbt.runtime.instance_variable_set("@db", mock)271 config = create_postgres_config()272 db_scripts = create_dir("databases")273 module_name = 'MyModule'274 table_names = ['[MyModule].[foo]']275 database = create_simple_db_definition(db_scripts, module_name, table_names)276 Dbt::Config.default_up_dirs = ['.', 'Dir1', 'Dir2']277 Dbt::Config.default_finalize_dirs = ['Dir3', 'Dir4']278 Dbt::Config.default_fixture_dir_name = 'foo'279 Dbt::Config.default_pre_create_dirs = ['db-pre-create']280 Dbt::Config.default_post_create_dirs = ['db-post-create']281 create_table_sql("db-pre-create", 'preCreate')282 create_table_sql("#{module_name}", 'a')283 create_table_sql("#{module_name}", 'b')284 create_table_sql("#{module_name}/Dir1", 'd')285 create_table_sql("#{module_name}/Dir1", 'c')286 create_table_sql("#{module_name}/Dir2", 'e')287 create_table_sql("#{module_name}/Dir2", 'f')288 create_fixture(module_name, 'foo')289 create_table_sql("#{module_name}/Dir3", 'g')290 create_table_sql("#{module_name}/Dir4", 'h')291 create_table_sql("db-post-create", 'postCreate')292 mock.expects(:open).with(config, true).in_sequence(@s)293 mock.expects(:drop).with(database, config).in_sequence(@s)294 mock.expects(:create_database).with(database, config).in_sequence(@s)295 mock.expects(:close).with().in_sequence(@s)296 mock.expects(:open).with(config, false).in_sequence(@s)297 expect_create_table(mock, '', 'db-pre-create/', 'preCreate')298 mock.expects(:create_schema).with(module_name).in_sequence(@s)299 expect_create_table(mock, module_name, '', 'a')300 expect_create_table(mock, module_name, '', 'b')301 expect_create_table(mock, module_name, 'Dir1/', 'c')302 expect_create_table(mock, module_name, 'Dir1/', 'd')303 expect_create_table(mock, module_name, 'Dir2/', 'e')304 expect_create_table(mock, module_name, 'Dir2/', 'f')305 expect_delete(mock, module_name, 'foo')306 expect_fixture(mock, module_name, 'foo')307 expect_create_table(mock, module_name, 'Dir3/', 'g')308 expect_create_table(mock, module_name, 'Dir4/', 'h')309 expect_create_table(mock, '', 'db-post-create/', 'postCreate')310 mock.expects(:close).with().in_sequence(@s)311 Dbt.runtime.create(database)312 end313 def psn(dir,table_name)314 "data/#{dir}/#{table_name}.sql"315 end316 def test_create_with_sql_from_package_import317 Dbt::Config.default_up_dirs = ['.', 'Dir1', 'Dir2']318 Dbt::Config.default_finalize_dirs = ['Dir3', 'Dir4']319 Dbt::Config.default_fixture_dir_name = 'foo'320 Dbt::Config.default_pre_create_dirs = ['db-pre-create']321 Dbt::Config.default_post_create_dirs = ['db-post-create']322 mock = Dbt::DbDriver.new323 Dbt.runtime.instance_variable_set('@db', mock)324 config = create_postgres_config()325 db_scripts = create_dir('databases')326 module_name = 'MyModule'327 packaged_definition = Dbt::RepositoryDefinition.new(:modules => [module_name],328 :table_map => {module_name => ['[MyModule].[foo]']})329 zipfile = create_zip('data/repository.yml' => packaged_definition.to_yaml,330 psn('db-pre-create', 'preCreate') => ct('preCreate'),331 "data/#{module_name}/#{Dbt::Config.default_fixture_dir_name}/#{module_name}.foo.yml" => "1:\n ID: 1\n",332 psn("#{module_name}", 'a') => ct('a'),333 psn("#{module_name}", 'b') => ct('b'),334 psn("#{module_name}/Dir1", 'd') => ct('d'),335 psn("#{module_name}/Dir1", 'c') => ct('c'),336 psn("#{module_name}/Dir2", 'e') => ct('e'),337 psn("#{module_name}/Dir2", 'f') => ct('f'),338 psn("#{module_name}/Dir3", 'g') => ct('g'),339 psn("#{module_name}/Dir4", 'h') => ct('h'),340 psn('db-post-create', 'postCreate') => ct('postCreate') )341 definition = Dbt::RepositoryDefinition.new(:modules => [], :table_map => {})342 File.open("#{db_scripts}/repository.yml",'w') do |f|343 f.write definition.to_yaml344 end345 database = Dbt.add_database(:default) do |db|346 db.rake_integration = false347 db.post_db_artifacts << zipfile348 db.search_dirs = [db_scripts]349 end350 Dbt.runtime.send(:perform_load_database_config, database)351 mock.expects(:open).with(config, true).in_sequence(@s)352 mock.expects(:drop).with(database, config).in_sequence(@s)353 mock.expects(:create_database).with(database, config).in_sequence(@s)354 mock.expects(:close).with().in_sequence(@s)355 mock.expects(:open).with(config, false).in_sequence(@s)356 expect_create_table(mock, '', 'db-pre-create/', 'preCreate')357 mock.expects(:create_schema).with(module_name).in_sequence(@s)358 expect_create_table(mock, module_name, '', 'a')359 expect_create_table(mock, module_name, '', 'b')360 expect_create_table(mock, module_name, 'Dir1/', 'c')361 expect_create_table(mock, module_name, 'Dir1/', 'd')362 expect_create_table(mock, module_name, 'Dir2/', 'e')363 expect_create_table(mock, module_name, 'Dir2/', 'f')364 expect_delete(mock, module_name, 'foo')365 expect_fixture(mock, module_name, 'foo')366 expect_create_table(mock, module_name, 'Dir3/', 'g')367 expect_create_table(mock, module_name, 'Dir4/', 'h')368 expect_create_table(mock, '', 'db-post-create/', 'postCreate')369 mock.expects(:close).with().in_sequence(@s)370 Dbt.runtime.create(database)371 end372 def test_create_with_sql_and_index_covering_partial373 mock = Dbt::DbDriver.new374 Dbt.runtime.instance_variable_set('@db', mock)375 config = create_postgres_config()376 db_scripts = create_dir('databases')377 module_name = 'MyModule'378 table_names = ['[MyModule].[foo]']379 database = create_simple_db_definition(db_scripts, module_name, table_names)380 Dbt::Config.default_up_dirs = ['Dir1']381 Dbt::Config.index_file_name = 'index2.txt'382 create_file("databases/#{module_name}/Dir1/index2.txt", "d.sql\ne.sql")383 create_table_sql("#{module_name}/Dir1", 'c')384 create_table_sql("#{module_name}/Dir1", 'd')385 create_table_sql("#{module_name}/Dir1", 'e')386 create_table_sql("#{module_name}/Dir1", 'f')387 mock.expects(:open).with(config, true).in_sequence(@s)388 mock.expects(:drop).with(database, config).in_sequence(@s)389 mock.expects(:create_database).with(database, config).in_sequence(@s)390 mock.expects(:close).with().in_sequence(@s)391 mock.expects(:open).with(config, false).in_sequence(@s)392 mock.expects(:create_schema).with(module_name).in_sequence(@s)393 expect_create_table(mock, module_name, 'Dir1/', 'd')394 expect_create_table(mock, module_name, 'Dir1/', 'e')395 expect_create_table(mock, module_name, 'Dir1/', 'c')396 expect_create_table(mock, module_name, 'Dir1/', 'f')397 mock.expects(:close).with().in_sequence(@s)398 Dbt.runtime.create(database)399 end400 def test_create_with_sql_and_index_covering_full401 mock = Dbt::DbDriver.new402 Dbt.runtime.instance_variable_set('@db', mock)403 config = create_postgres_config()404 db_scripts = create_dir('databases')405 module_name = 'MyModule'406 table_names = ['[MyModule].[foo]']407 database = create_simple_db_definition(db_scripts, module_name, table_names)408 Dbt::Config.default_up_dirs = ['Dir1']409 Dbt::Config.index_file_name = 'index2.txt'410 create_file("databases/#{module_name}/Dir1/index2.txt", "d.sql\ne.sql")411 create_table_sql("#{module_name}/Dir1", 'd')412 create_table_sql("#{module_name}/Dir1", 'e')413 mock.expects(:open).with(config, true).in_sequence(@s)414 mock.expects(:drop).with(database, config).in_sequence(@s)415 mock.expects(:create_database).with(database, config).in_sequence(@s)416 mock.expects(:close).with().in_sequence(@s)417 mock.expects(:open).with(config, false).in_sequence(@s)418 mock.expects(:create_schema).with(module_name).in_sequence(@s)419 expect_create_table(mock, module_name, 'Dir1/', 'd')420 expect_create_table(mock, module_name, 'Dir1/', 'e')421 mock.expects(:close).with().in_sequence(@s)422 Dbt.runtime.create(database)423 end424 def test_create_with_sql_and_index_with_additional425 mock = Dbt::DbDriver.new426 Dbt.runtime.instance_variable_set('@db', mock)427 config = create_postgres_config()428 db_scripts = create_dir('databases')429 module_name = 'MyModule'430 table_names = ['[MyModule].[foo]']431 database = create_simple_db_definition(db_scripts, module_name, table_names)432 Dbt::Config.default_up_dirs = ['Dir1']433 Dbt::Config.index_file_name = 'index2.txt'434 create_file("databases/#{module_name}/Dir1/index2.txt", "d.sql\ne.sql\nf.sql")435 create_table_sql("#{module_name}/Dir1", 'd')436 create_table_sql("#{module_name}/Dir1", 'e')437 mock.expects(:open).with(config, true).in_sequence(@s)438 mock.expects(:drop).with(database, config).in_sequence(@s)439 mock.expects(:create_database).with(database, config).in_sequence(@s)440 mock.expects(:close).with().in_sequence(@s)441 mock.expects(:open).with(config, false).in_sequence(@s)442 mock.expects(:create_schema).with(module_name).in_sequence(@s)443 mock.expects(:close).with().in_sequence(@s)444 assert_raises(RuntimeError) do445 Dbt.runtime.create(database)446 end447 end448 def test_drop449 mock = Dbt::DbDriver.new450 Dbt.runtime.instance_variable_set('@db', mock)451 config = create_postgres_config()452 db_scripts = create_dir('databases')453 module_name = 'MyModule'454 table_names = ['[MyModule].[foo]', '[MyModule].[bar]']455 database = create_simple_db_definition(db_scripts, module_name, table_names)456 mock.expects(:open).with(config, true).in_sequence(@s)457 mock.expects(:drop).with(database, config).in_sequence(@s)458 mock.expects(:close).with().in_sequence(@s)459 Dbt.runtime.drop(database)460 end461 def test_import462 mock = Dbt::DbDriver.new463 Dbt.runtime.instance_variable_set('@db', mock)464 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))465 db_scripts = create_dir('databases')466 module_name = 'MyModule'467 table_names = ['[MyModule].[foo]', '[MyModule].[bar]', '[MyModule].[baz]']468 database = create_simple_db_definition(db_scripts, module_name, table_names)469 database.separate_import_task = true470 import = database.add_import(:default, {})471 mock.expects(:open).with(config, false).in_sequence(@s)472 expect_delete_for_table_import(mock, module_name, 'baz')473 expect_delete_for_table_import(mock, module_name, 'bar')474 expect_delete_for_table_import(mock, module_name, 'foo')475 expect_default_table_import(mock, import, module_name, 'foo')476 expect_default_table_import(mock, import, module_name, 'bar')477 expect_default_table_import(mock, import, module_name, 'baz')478 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)479 mock.expects(:post_database_import).with(import).in_sequence(@s)480 mock.expects(:close).with().in_sequence(@s)481 Dbt.runtime.database_import(database.import_by_name(:default), nil)482 end483 def test_import_with_IMPORT_RESUME_AT484 mock = Dbt::DbDriver.new485 Dbt.runtime.instance_variable_set('@db', mock)486 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))487 db_scripts = create_dir('databases')488 module_name = 'MyModule'489 table_names = ['[MyModule].[foo]', '[MyModule].[bar]', '[MyModule].[baz]']490 database = create_simple_db_definition(db_scripts, module_name, table_names)491 database.separate_import_task = true492 import = database.add_import(:default, {})493 mock.expects(:open).with(config, false).in_sequence(@s)494 expect_delete_for_table_import(mock, module_name, 'bar')495 expect_default_table_import(mock, import, module_name, 'bar')496 expect_default_table_import(mock, import, module_name, 'baz')497 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)498 mock.expects(:post_database_import).with(import).in_sequence(@s)499 mock.expects(:close).with()500 ENV['IMPORT_RESUME_AT'] = 'MyModule.bar'501 Dbt.runtime.database_import(database.import_by_name(:default), nil)502 end503 def test_import_by_sql504 mock = Dbt::DbDriver.new505 Dbt.runtime.instance_variable_set('@db', mock)506 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))507 db_scripts = create_dir('databases')508 module_name = 'MyModule'509 table_names = ['[MyModule].[foo]']510 database = create_simple_db_definition(db_scripts, module_name, table_names)511 database.separate_import_task = true512 import = database.add_import(:default, {})513 Dbt::Config.default_import_dir = 'zzzz'514 import_sql = 'INSERT INTO DBT_TEST.[foo]'515 create_file("databases/#{module_name}/zzzz/MyModule.foo.sql", import_sql)516 mock.expects(:open).with(config, false).in_sequence(@s)517 expect_delete_for_table_import(mock, module_name, 'foo')518 expect_pre_table_import(mock, import, module_name, 'foo', 'S')519 mock.expects(:execute).with(import_sql, true).in_sequence(@s)520 expect_post_table_import(mock, import, module_name, 'foo')521 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)522 mock.expects(:post_database_import).with(import).in_sequence(@s)523 mock.expects(:close).with().in_sequence(@s)524 Dbt.runtime.database_import(database.import_by_name(:default), nil)525 end526 def test_import_by_fixture527 mock = Dbt::DbDriver.new528 Dbt.runtime.instance_variable_set('@db', mock)529 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))530 db_scripts = create_dir('databases')531 module_name = 'MyModule'532 table_names = ['[MyModule].[foo]']533 database = create_simple_db_definition(db_scripts, module_name, table_names)534 database.separate_import_task = true535 import = database.add_import(:default, {})536 Dbt::Config.default_import_dir = 'zzzz'537 fixture_data = "1:\n ID: 1\n"538 create_file('databases/MyModule/zzzz/MyModule.foo.yml', fixture_data)539 mock.expects(:open).with(config, false).in_sequence(@s)540 expect_delete_for_table_import(mock, module_name, 'foo')541 expect_pre_table_import(mock, import, module_name, 'foo', 'F')542 mock.expects(:pre_fixture_import).with('[MyModule].[foo]').in_sequence(@s)543 mock.expects(:insert).with('[MyModule].[foo]', 'ID' => 1).in_sequence(@s)544 mock.expects(:post_fixture_import).with('[MyModule].[foo]').in_sequence(@s)545 expect_post_table_import(mock, import, module_name, 'foo')546 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)547 mock.expects(:post_database_import).with(import).in_sequence(@s)548 mock.expects(:close).with().in_sequence(@s)549 Dbt.runtime.database_import(database.import_by_name(:default), nil)550 end551 def test_import_using_pre_post_dirs552 mock = Dbt::DbDriver.new553 Dbt.runtime.instance_variable_set('@db', mock)554 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))555 db_scripts = create_dir('databases')556 module_name = 'MyModule'557 table_names = ['[MyModule].[foo]']558 database = create_simple_db_definition(db_scripts, module_name, table_names)559 database.separate_import_task = true560 import = database.add_import(:default, {})561 Dbt::Config.default_pre_import_dirs = ['a', 'b']562 pre_import_sql = 'SELECT 1'563 create_file('databases/a/yyy.sql', pre_import_sql)564 pre_import_sql_2 = 'SELECT 2'565 create_file('databases/b/qqq.sql', pre_import_sql_2)566 Dbt::Config.default_post_import_dirs = ['c', 'd']567 post_import_sql = 'SELECT 3'568 create_file('databases/c/xxx.sql', post_import_sql)569 post_import_sql_2 = 'SELECT 4'570 create_file('databases/d/zzz.sql', post_import_sql_2)571 mock.expects(:open).with(config, false).in_sequence(@s)572 Dbt.runtime.expects(:info).with(' : a/yyy.sql').in_sequence(@s)573 mock.expects(:execute).with(pre_import_sql, true).in_sequence(@s)574 Dbt.runtime.expects(:info).with(' : b/qqq.sql').in_sequence(@s)575 mock.expects(:execute).with(pre_import_sql_2, true).in_sequence(@s)576 expect_delete_for_table_import(mock, module_name, 'foo')577 expect_default_table_import(mock, import, module_name, 'foo')578 mock.expects(:post_data_module_import).with(import, module_name).in_sequence(@s)579 Dbt.runtime.expects(:info).with(' : c/xxx.sql').in_sequence(@s)580 mock.expects(:execute).with(post_import_sql, true).in_sequence(@s)581 Dbt.runtime.expects(:info).with(' : d/zzz.sql').in_sequence(@s)582 mock.expects(:execute).with(post_import_sql_2, true).in_sequence(@s)583 mock.expects(:post_database_import).with(import).in_sequence(@s)584 mock.expects(:close).with()585 Dbt.runtime.database_import(database.import_by_name(:default), nil)586 end587 def test_migrate588 mock = Dbt::DbDriver.new589 Dbt.runtime.instance_variable_set('@db', mock)590 config = create_postgres_config()591 db_scripts = create_dir('databases')592 module_name = 'MyModule'593 table_names = ['[MyModule].[foo]']594 database = create_simple_db_definition(db_scripts, module_name, table_names)595 database.migrations = true596 Dbt::Config.default_migrations_dir_name = 'migrate22'597 migrate_sql_1 = 'SELECT 1'598 create_file('databases/migrate22/001_x.sql', migrate_sql_1)599 migrate_sql_2 = 'SELECT 2'600 create_file('databases/migrate22/002_x.sql', migrate_sql_2)601 migrate_sql_3 = 'SELECT 3'602 create_file('databases/migrate22/003_x.sql', migrate_sql_3)603 mock.expects(:open).with(config, false).in_sequence(@s)604 expect_should_migrate(mock, 'default', '001_x', true)605 expect_migrate(mock, 'default', '001_x', migrate_sql_1)606 expect_should_migrate(mock, 'default', '002_x', true)607 expect_migrate(mock, 'default', '002_x', migrate_sql_2)608 expect_should_migrate(mock, 'default', '003_x', true)609 expect_migrate(mock, 'default', '003_x', migrate_sql_3)610 mock.expects(:close).with().in_sequence(@s)611 Dbt.runtime.migrate(database)612 end613 def test_migrate_from_major_version614 mock = Dbt::DbDriver.new615 Dbt.runtime.instance_variable_set('@db', mock)616 config = create_postgres_config()617 db_scripts = create_dir('databases')618 module_name = 'MyModule'619 table_names = ['[MyModule].[foo]']620 database = create_simple_db_definition(db_scripts, module_name, table_names)621 database.migrations = true622 database.version = 'Version_1'623 Dbt::Config.default_migrations_dir_name = 'migrate22'624 migrate_sql_1 = 'SELECT 1'625 create_file('databases/migrate22/001_x.sql', migrate_sql_1)626 migrate_sql_2 = 'SELECT 2'627 create_file("databases/migrate22/002_Release-#{database.version}.sql", migrate_sql_2)628 migrate_sql_3 = 'SELECT 3'629 create_file('databases/migrate22/003_z.sql', migrate_sql_3)630 mock.expects(:open).with(config, false).in_sequence(@s)631 expect_should_migrate(mock, 'default', '001_x', true)632 expect_mark_migration_as_run(mock, 'default', '001_x')633 expect_should_migrate(mock, 'default', "002_Release-#{database.version}", true)634 expect_mark_migration_as_run(mock, 'default', "002_Release-#{database.version}")635 expect_should_migrate(mock, 'default', '003_z', true)636 expect_migrate(mock, 'default', '003_z', migrate_sql_3)637 mock.expects(:close).with().in_sequence(@s)638 Dbt.runtime.migrate(database)639 end640 def test_migrate_with_existing_migrations_applied641 mock = Dbt::DbDriver.new642 Dbt.runtime.instance_variable_set('@db', mock)643 config = create_postgres_config()644 db_scripts = create_dir('databases')645 module_name = 'MyModule'646 table_names = ['[MyModule].[foo]']647 database = create_simple_db_definition(db_scripts, module_name, table_names)648 database.migrations = true649 Dbt::Config.default_migrations_dir_name = 'migrate22'650 migrate_sql_1 = 'SELECT 1'651 create_file('databases/migrate22/001_x.sql', migrate_sql_1)652 migrate_sql_2 = 'SELECT 2'653 create_file('databases/migrate22/002_x.sql', migrate_sql_2)654 migrate_sql_3 = 'SELECT 3'655 create_file('databases/migrate22/003_x.sql', migrate_sql_3)656 mock.expects(:open).with(config, false).in_sequence(@s)657 expect_should_migrate(mock, 'default', '001_x', false)658 expect_should_migrate(mock, 'default', '002_x', false)659 expect_should_migrate(mock, 'default', '003_x', true)660 expect_migrate(mock, 'default', '003_x', migrate_sql_3)661 mock.expects(:close).with().in_sequence(@s)662 Dbt.runtime.migrate(database)663 end664 def test_create_with_migrations665 mock = Dbt::DbDriver.new666 Dbt.runtime.instance_variable_set('@db', mock)667 config = create_postgres_config()668 db_scripts = create_dir('databases')669 module_name = 'MyModule'670 table_names = ['[MyModule].[foo]', '[MyModule].[bar]', '[MyModule].[baz]']671 database = create_simple_db_definition(db_scripts, module_name, table_names)672 database.migrations = true673 database.migrations_applied_at_create = false674 Dbt::Config.default_migrations_dir_name = 'migrate22'675 migrate_sql_1 = 'SELECT 1'676 create_file('databases/migrate22/001_x.sql', migrate_sql_1)677 mock.expects(:open).with(config, true).in_sequence(@s)678 mock.expects(:drop).with(database, config).in_sequence(@s)679 mock.expects(:create_database).with(database, config).in_sequence(@s)680 mock.expects(:close).with().in_sequence(@s)681 mock.expects(:open).with(config, false).in_sequence(@s)682 mock.expects(:create_schema).with(module_name).in_sequence(@s)683 mock.expects(:setup_migrations).with().in_sequence(@s)684 expect_migrate(mock, 'default', '001_x', migrate_sql_1)685 mock.expects(:close).with().in_sequence(@s)686 Dbt.runtime.create(database)687 end688 def test_create_with_migrations_already_applied689 mock = Dbt::DbDriver.new690 Dbt.runtime.instance_variable_set('@db', mock)691 config = create_postgres_config()692 db_scripts = create_dir('databases')693 module_name = 'MyModule'694 table_names = ['[MyModule].[foo]', '[MyModule].[bar]', '[MyModule].[baz]']695 database = create_simple_db_definition(db_scripts, module_name, table_names)696 database.migrations = true697 database.migrations_applied_at_create = true698 Dbt::Config.default_migrations_dir_name = 'migrate22'699 migrate_sql_1 = 'SELECT 1'700 create_file('databases/migrate22/001_x.sql', migrate_sql_1)701 mock.expects(:open).with(config, true).in_sequence(@s)702 mock.expects(:drop).with(database, config).in_sequence(@s)703 mock.expects(:create_database).with(database, config).in_sequence(@s)704 mock.expects(:close).with().in_sequence(@s)705 mock.expects(:open).with(config, false).in_sequence(@s)706 mock.expects(:create_schema).with(module_name).in_sequence(@s)707 mock.expects(:setup_migrations).with().in_sequence(@s)708 expect_mark_migration_as_run(mock, 'default', '001_x')709 mock.expects(:close).with().in_sequence(@s)710 Dbt.runtime.create(database)711 end712 def test_load_dataset713 mock = Dbt::DbDriver.new714 Dbt.runtime.instance_variable_set('@db', mock)715 config = create_postgres_config()716 db_scripts = create_dir('databases')717 module_name = 'MyModule'718 database = create_db_definition(db_scripts,719 'MyModule' => ['[MyModule].[foo]', '[MyModule].[bar]'],720 'MyOtherModule' => ['[MyOtherModule].[baz]'])721 Dbt::Config.default_datasets_dir_name = 'mydatasets'722 create_file('databases/MyModule/mydatasets/mydataset/MyModule.foo.yml', "1:\n ID: 1\n")723 create_file('databases/MyModule/mydatasets/mydataset/MyModule.bar.yml', "1:\n ID: 1\n")724 create_file('databases/MyOtherModule/mydatasets/mydataset/MyOtherModule.baz.yml', "1:\n ID: 1\n")725 mock.expects(:open).with(config, false).in_sequence(@s)726 expect_delete(mock, 'MyOtherModule', 'baz')727 expect_delete(mock, module_name, 'bar')728 expect_delete(mock, module_name, 'foo')729 expect_fixture(mock, module_name, 'foo')730 expect_fixture(mock, module_name, 'bar')731 expect_fixture(mock, 'MyOtherModule', 'baz')732 mock.expects(:close).with().in_sequence(@s)733 Dbt.runtime.load_dataset(database, 'mydataset')734 end735 def test_import_with_module_group736 mock = Dbt::DbDriver.new737 Dbt.runtime.instance_variable_set('@db', mock)738 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))739 db_scripts = create_dir('databases')740 database = create_db_definition(db_scripts,741 'MyModule' => ['[MyModule].[foo]', '[MyModule].[bar]'],742 'MyOtherModule' => ['[MyOtherModule].[baz]'],743 'MyThirdModule' => ['[MyThirdModule].[biz]'])744 module_group = database.add_module_group('zz', :modules => ['MyOtherModule','MyThirdModule'], :import_enabled => true)745 assert_equal module_group.modules, ['MyOtherModule', 'MyThirdModule']746 assert_equal module_group.import_enabled?, true747 import = database.add_import(:default, {})748 mock.expects(:open).with(config, false).in_sequence(@s)749 expect_delete_for_table_import(mock, 'MyOtherModule', 'baz')750 expect_default_table_import(mock, import, 'MyOtherModule', 'baz')751 mock.expects(:post_data_module_import).with(import, 'MyOtherModule').in_sequence(@s)752 # TODO: This is wrong behaviour. All of deletes should occur first753 expect_delete_for_table_import(mock, 'MyThirdModule', 'biz')754 expect_default_table_import(mock, import, 'MyThirdModule', 'biz')755 mock.expects(:post_data_module_import).with(import, 'MyThirdModule').in_sequence(@s)756 mock.expects(:post_database_import).with(import).in_sequence(@s)757 mock.expects(:close).with().in_sequence(@s)758 Dbt.runtime.database_import(database.import_by_name(:default), database.module_group_by_name('zz'))759 end760 def test_module_group_up761 mock = Dbt::DbDriver.new762 Dbt.runtime.instance_variable_set('@db', mock)763 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))764 db_scripts = create_dir('databases')765 database = create_db_definition(db_scripts,766 'MyModule' => ['[MyModule].[foo]', '[MyModule].[bar]'],767 'MyOtherModule' => ['[MyOtherModule].[baz]'],768 'MyThirdModule' => ['[MyThirdModule].[biz]'])769 module_group = database.add_module_group('zz', :modules => ['MyOtherModule','MyThirdModule'])770 assert_equal module_group.modules, ['MyOtherModule', 'MyThirdModule']771 Dbt::Config.default_up_dirs = ['.']772 create_table_sql('MyOtherModule', 'a')773 create_table_sql('MyThirdModule', 'b')774 mock.expects(:open).with(config, false).in_sequence(@s)775 mock.expects(:create_schema).with('MyOtherModule').in_sequence(@s)776 expect_create_table(mock, 'MyOtherModule', '', 'a')777 mock.expects(:create_schema).with('MyThirdModule').in_sequence(@s)778 expect_create_table(mock, 'MyThirdModule', '', 'b')779 mock.expects(:close).with().in_sequence(@s)780 Dbt.runtime.up_module_group(database.module_group_by_name('zz'))781 end782 def test_module_group_down783 mock = Dbt::DbDriver.new784 Dbt.runtime.instance_variable_set('@db', mock)785 config = create_postgres_config({}, 'import' => base_postgres_config().merge('database' => 'IMPORT_DB'))786 db_scripts = create_dir('databases')787 database = create_db_definition(db_scripts,788 'MyModule' => ['[MyModule].[foo]', '[MyModule].[bar]'],789 'MyOtherModule' => ['[MyOtherModule].[baz]', '[MyOtherModule].[bark]'],790 'MyThirdModule' => ['[MyThirdModule].[biz]'])791 module_group = database.add_module_group('zz', :modules => ['MyOtherModule', 'MyThirdModule'])792 database.repository.schema_overrides['MyThirdModule'] = 'My3rdSchema'793 assert_equal module_group.modules, ['MyOtherModule', 'MyThirdModule']794 Dbt::Config.default_up_dirs = ['.']795 Dbt::Config.default_down_dirs = ['Down2', 'Down3']796 create_table_sql('MyOtherModule/Down2', 'a')797 create_table_sql('MyThirdModule/Down3', 'b')798 mock.expects(:open).with(config, false).in_sequence(@s)799 expect_create_table(mock, 'MyThirdModule', 'Down3/', 'b')800 mock.expects(:drop_schema).with('My3rdSchema', ['[MyThirdModule].[biz]']).in_sequence(@s)801 expect_create_table(mock, 'MyOtherModule', 'Down2/', 'a')802 mock.expects(:drop_schema).with('MyOtherModule', ['[MyOtherModule].[bark]','[MyOtherModule].[baz]']).in_sequence(@s)803 mock.expects(:close).with().in_sequence(@s)804 Dbt.runtime.down_module_group(database.module_group_by_name('zz'))805 end806 def test_dump_database_to_fixtures807 mock = Dbt::DbDriver.new808 Dbt.runtime.instance_variable_set('@db', mock)809 fixture_dir = create_dir('output_fixtures')810 config = create_postgres_config()811 db_scripts = create_dir('databases')812 table_names = ['[MyModule].[tblTable1]', '[MyModule].[tblTable2]']813 module_name = 'MyModule'814 database = create_simple_db_definition(db_scripts, module_name, table_names)815 Dbt::Config.default_fixture_dir_name = 'fixturesXX'816 expected_table2_sql = 'SELECT * FROM [MyModule].[tblTable2] ORDER BY ID'817 Object.const_set(:DUMP_SQL_FOR_MyModule_tblTable2, expected_table2_sql)818 begin819 mock.expects(:open).with(config, false).in_sequence(@s)820 Dbt.runtime.expects(:info).with('Dumping [MyModule].[tblTable1]').in_sequence(@s)821 mock.expects(:query).with('SELECT * FROM [MyModule].[tblTable1]').returns([{'ID' => 1}, {'ID' => 2}]).in_sequence(@s)822 Dbt.runtime.expects(:info).with('Dumping [MyModule].[tblTable2]').in_sequence(@s)823 mock.expects(:query).with(expected_table2_sql).returns([{'ID' => 1}, {'ID' => 2}]).in_sequence(@s)824 mock.expects(:close).with().in_sequence(@s)825 Dbt.runtime.dump_database_to_fixtures(database, fixture_dir)826 assert_file_exist("#{fixture_dir}/MyModule/fixturesXX/MyModule.tblTable1.yml")827 assert_file_exist("#{fixture_dir}/MyModule/fixturesXX/MyModule.tblTable2.yml")828 ensure829 Object.send(:remove_const, :DUMP_SQL_FOR_MyModule_tblTable2)830 end831 end832 def test_dump_database_to_fixtures_with_data_set833 mock = Dbt::DbDriver.new834 Dbt.runtime.instance_variable_set('@db', mock)835 fixture_dir = create_dir('output_fixtures')836 config = create_postgres_config()837 db_scripts = create_dir('databases')838 table_names = ['[MyModule].[tblTable1]']839 module_name = 'MyModule'840 database = create_simple_db_definition(db_scripts, module_name, table_names)841 data_set = 'foo'842 Dbt::Config.default_datasets_dir_name = 'dataset123'843 mock.expects(:open).with(config, false).in_sequence(@s)844 Dbt.runtime.expects(:info).with('Dumping [MyModule].[tblTable1]').in_sequence(@s)845 mock.expects(:query).with('SELECT * FROM [MyModule].[tblTable1]').returns([{'ID' => 1}, {'ID' => 2}]).in_sequence(@s)846 mock.expects(:close).with().in_sequence(@s)847 Dbt.runtime.dump_database_to_fixtures(database, fixture_dir, :data_set => data_set)848 assert_file_exist("#{fixture_dir}/MyModule/dataset123/foo/MyModule.tblTable1.yml")849 end850 def test_dump_database_to_fixtures_with_filter851 mock = Dbt::DbDriver.new852 Dbt.runtime.instance_variable_set('@db', mock)853 fixture_dir = create_dir('output_fixtures')854 config = create_postgres_config()855 db_scripts = create_dir('databases')856 table_names = ['[MyModule].[tblTable1]', '[MyModule].[tblTable2]']857 module_name = 'MyModule'858 database = create_simple_db_definition(db_scripts, module_name, table_names)859 filter = Proc.new {|t| t == '[MyModule].[tblTable1]'}860 Dbt::Config.default_fixture_dir_name = 'fixturesXX'861 mock.expects(:open).with(config, false).in_sequence(@s)862 Dbt.runtime.expects(:info).with('Dumping [MyModule].[tblTable1]').in_sequence(@s)863 mock.expects(:query).with('SELECT * FROM [MyModule].[tblTable1]').returns([{'ID' => 1}, {'ID' => 2}]).in_sequence(@s)864 mock.expects(:close).with().in_sequence(@s)865 Dbt.runtime.dump_database_to_fixtures(database, fixture_dir, :filter => filter)866 assert_file_exist("#{fixture_dir}/MyModule/fixturesXX/MyModule.tblTable1.yml")867 end868 def test_collect_fileset_for_hash869 db_scripts = create_dir('databases')870 module_name = 'MyModule'871 table_names = ['[MyModule].[foo]']872 database = create_simple_db_definition(db_scripts, module_name, table_names)873 Dbt::Config.default_up_dirs = ['.', 'Dir1', 'Dir2']874 Dbt::Config.default_finalize_dirs = ['Dir3', 'Dir4']875 Dbt::Config.default_fixture_dir_name = 'foo'876 Dbt::Config.default_pre_create_dirs = ['db-pre-create']877 Dbt::Config.default_post_create_dirs = ['db-post-create']878 Dbt::Config.default_post_create_dirs = ['db-post-create']879 files = []880 files << create_table_sql('db-pre-create', 'preCreate')881 files << create_table_sql("#{module_name}", 'a')882 files << create_table_sql("#{module_name}", 'b')883 files << create_table_sql("#{module_name}/Dir1", 'd')884 files << create_table_sql("#{module_name}/Dir1", 'c')885 files << create_table_sql("#{module_name}/Dir2", 'e')886 files << create_table_sql("#{module_name}/Dir2", 'f')887 files << create_fixture(module_name, 'foo')888 files << create_table_sql("#{module_name}/Dir3", 'g')889 files << create_table_sql("#{module_name}/Dir4", 'h')890 files << create_table_sql('db-post-create', 'postCreate')891 database.separate_import_task = true892 import = database.add_import(:default, {})893 import.pre_import_dirs = ['pre-imp1', 'pre-imp2']894 import.post_import_dirs = ['post-imp1', 'post-imp2']895 Dbt::Config.default_import_dir = 'zzzz'896 import_sql = 'INSERT INTO DBT_TEST.[foo]'897 files << create_file('databases/pre-imp1/a.sql', import_sql)898 files << create_file('databases/pre-imp2/a.sql', import_sql)899 files << create_file("databases/#{module_name}/zzzz/MyModule.foo.sql", import_sql)900 files << create_file("databases/#{module_name}/zzzz/MyModule.foo.yml", import_sql)901 files << create_file('databases/post-imp1/a.sql', import_sql)902 files << create_file('databases/post-imp2/a.sql', import_sql)903 database.migrations = true904 Dbt::Config.default_migrations_dir_name = 'migrate22'905 migrate_sql_1 = 'SELECT 1'906 files << create_file('databases/migrate22/001_x.sql', migrate_sql_1)907 # Should not be collected, as in an irrelevant directories908 create_table_sql("#{module_name}/Elsewhere", 'aaa')909 create_table_sql("#{module_name}aa/Dir1", 'aaa')910 # Should not be collected, only imports of sql and yml are included911 create_file("databases/#{module_name}/zzzz/MyModule.foo.ignore", import_sql)912 assert_equal(files.sort, Dbt.runtime.send(:collect_fileset_for_hash, database).map { |f| f.nil? ? 'alert nil' : f.gsub(/\/\.\//, '/') }.sort)913 end914 def test_hash_files_with_no_files_doesnt_crash915 Dbt.runtime.send(:hash_files, nil, [])916 end917 def test_hash_files918 database = create_simple_db_definition(create_dir('databases'), 'MyModule', [])919 create_dir('databases/generated')920 create_file('databases/generated/MyModule/base.sql', 'some')921 create_file('databases/generated/MyModule/types/typeA.sql', 'content')922 create_file('databases/generated/MyModule/views/viewA.sql', 'here')923 create_file('databases/generated/MyModule/views/viewB.sql', 'here')924 hash_1 = Dbt.runtime.send(:hash_files, database, ['databases/generated/MyModule/base.sql',925 'databases/generated/MyModule/types/typeA.sql',926 'databases/generated/MyModule/views/viewA.sql'])927 # Same content, different files928 hash_2 = Dbt.runtime.send(:hash_files, database, ['databases/generated/MyModule/base.sql',929 'databases/generated/MyModule/types/typeA.sql',930 'databases/generated/MyModule/views/viewB.sql'])931 assert_not_equal(hash_1, hash_2)932 create_file('databases/generated/MyModule/types/typeA.sql', 'here')933 create_file('databases/generated/MyModule/views/viewA.sql', 'content')934 # Same files, content switched between files935 hash_3 = Dbt.runtime.send(:hash_files, database, ['databases/generated/MyModule/base.sql',936 'databases/generated/MyModule/types/typeA.sql',937 'databases/generated/MyModule/views/viewA.sql'])938 assert_not_equal(hash_1, hash_3)939 create_file('databases/generated/MyModule/types/typeA.sql', 'content')940 create_file('databases/generated/MyModule/views/viewA.sql', 'here')941 # Same files, recreated942 hash_4 = Dbt.runtime.send(:hash_files, database, ['databases/generated/MyModule/base.sql',943 'databases/generated/MyModule/types/typeA.sql',944 'databases/generated/MyModule/views/viewA.sql'])945 assert_equal(hash_1, hash_4)946 end947 def setup948 super949 @s = sequence('main')950 end951 def create_table_sql(dir, table_name)952 create_file("databases/#{dir}/#{table_name}.sql", ct(table_name))953 end954 def ct(table_name)955 "CREATE TABLE [#{table_name}]"956 end957 def create_fixture(module_name, table_name)958 create_file("databases/#{module_name}/#{Dbt::Config.default_fixture_dir_name}/#{module_name}.#{table_name}.yml", "1:\n ID: 1\n")959 end960 def expect_create_table(mock, module_name, dirname, table_name, seq = true)961 Dbt.runtime.expects(:info).with("#{'%-15s' % module_name}: #{dirname}#{table_name}.sql").in_sequence(@s)962 mock.expects(:execute).with("CREATE TABLE [#{table_name}]", false).in_sequence(@s)963 end964 def expect_delete(mock, module_name, table_name)965 mock.expects(:execute).with("DELETE FROM [#{module_name}].[#{table_name}]", false).in_sequence(@s)966 end967 def expect_fixture(mock, module_name, table_name)968 Dbt.runtime.expects(:info).with("Fixture : #{module_name}.#{table_name}").in_sequence(@s)969 mock.expects(:pre_fixture_import).with("[#{module_name}].[#{table_name}]").in_sequence(@s)970 mock.expects(:insert).with("[#{module_name}].[#{table_name}]", 'ID' => 1).in_sequence(@s)971 mock.expects(:post_fixture_import).with("[#{module_name}].[#{table_name}]").in_sequence(@s)972 end973 def expect_migrate(mock, database_key, migration_name, sql)974 Dbt.runtime.expects(:info).with("Migration: #{migration_name}.sql").in_sequence(@s)975 mock.expects(:execute).with(sql, false).in_sequence(@s)976 expect_mark_migration_as_run(mock, database_key, migration_name)977 end978 def expect_should_migrate(mock, database_key, migration_name, result)979 mock.expects(:'should_migrate?').with(database_key, migration_name).returns(result).in_sequence(@s)980 end981 def expect_mark_migration_as_run(mock, database_key, migration_name)982 mock.expects(:mark_migration_as_run).with(database_key, migration_name).in_sequence(@s)983 end984 def expect_default_table_import(mock, import_definition, module_name, table_name)985 expect_pre_table_import(mock, import_definition, module_name, table_name, 'D')986 mock.expects(:column_names_for_table).with("[#{module_name}].[#{table_name}]").returns(['[ID]']).in_sequence(@s)987 mock.expects(:execute).with("INSERT INTO DBT_TEST.[#{module_name}].[#{table_name}]([ID])\n SELECT [ID] FROM IMPORT_DB.[#{module_name}].[#{table_name}]\n", true).in_sequence(@s)988 expect_post_table_import(mock, import_definition, module_name, table_name)989 end990 def expect_pre_table_import(mock, import_definition, module_name, table_name, import_type)991 mock.expects(:pre_table_import).with(import_definition, "[#{module_name}].[#{table_name}]").in_sequence(@s)992 Dbt.runtime.expects(:info).with("#{'%-15s' % module_name}: Importing #{module_name}.#{table_name} (By #{import_type})").in_sequence(@s)993 end994 def expect_post_table_import(mock, import_definition, module_name, table_name)995 mock.expects(:post_table_import).with(import_definition, "[#{module_name}].[#{table_name}]").in_sequence(@s)996 end997 def expect_delete_for_table_import(mock, module_name, table_name)998 Dbt.runtime.expects(:info).with("Deleting #{module_name}.#{table_name}").in_sequence(@s)999 expect_delete(mock, module_name, table_name)1000 end1001 def create_simple_db_definition(db_scripts, module_name, table_names)1002 Dbt.add_database(:default) do |db|1003 db.rake_integration = false1004 db.repository.modules = [module_name]1005 db.repository.table_map = {module_name => table_names}1006 db.search_dirs = [db_scripts]1007 end1008 end1009 def create_db_definition(db_scripts, table_map)1010 Dbt.add_database(:default) do |db|1011 db.rake_integration = false1012 db.repository.modules = table_map.keys1013 db.repository.table_map = table_map1014 db.search_dirs = [db_scripts]1015 end1016 end1017 def create_postgres_config(config = {}, top_level_config = {})1018 Dbt::Config.driver = 'postgres'1019 Dbt.repository.configuration_data = {1020 Dbt::Config.environment => base_postgres_config(config)1021 }.merge(top_level_config)1022 Dbt.repository.configuration_for_key(Dbt::Config.environment)1023 end1024 def base_postgres_config(config = {})1025 {1026 'database' => 'DBT_TEST',1027 'username' => ENV['USER'],1028 'password' => 'letmein',1029 'host' => '127.0.0.1',1030 'port' => 54321031 }.merge(config)1032 end1033end...
ruby_generator_spec.rb
Source:ruby_generator_spec.rb
...15 def source16 <<-CODE17 type MyModule::FirstGenerated = Object[{18 attributes => {19 name => String,20 age => { type => Integer, value => 30 },21 what => { type => String, value => 'what is this', kind => constant }22 }23 }]24 type MyModule::SecondGenerated = Object[{25 parent => MyModule::FirstGenerated,26 attributes => {27 address => String,28 zipcode => String,29 email => String,30 another => { type => Optional[MyModule::FirstGenerated], value => undef },31 number => Integer32 }33 }]34 CODE35 end36 context 'when generating anonymous classes' do37 scope = nil38 let(:first_type) { parser.parse('MyModule::FirstGenerated', scope) }39 let(:second_type) { parser.parse('MyModule::SecondGenerated', scope) }40 let(:first) { generator.create_class(first_type) }41 let(:second) { generator.create_class(second_type) }42 before(:each) do43 eval_and_collect_notices(source) do |topscope, catalog|44 scope = topscope45 end46 end47 after(:each) { typeset = nil }48 context 'the generated class' do49 it 'inherits the PuppetObject module' do50 expect(first < PuppetObject).to be_truthy51 end52 it 'is the superclass of a generated subclass' do53 expect(second < first).to be_truthy54 end55 end56 context 'the #create class method' do57 it 'has an arity that reflects optional arguments' do58 expect(first.method(:create).arity).to eql(-2)59 expect(second.method(:create).arity).to eql(-6)60 end61 it 'creates an instance of the class' do62 inst = first.create('Bob Builder', 52)63 expect(inst).to be_a(first)64 expect(inst.name).to eq('Bob Builder')65 expect(inst.age).to eq(52)66 end67 it 'will perform type assertion of the arguments' do68 expect { first.create('Bob Builder', '52') }.to(69 raise_error(TypeAssertionError,70 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got String')71 )72 end73 it 'will not accept nil as given value for an optional parameter that does not accept nil' do74 expect { first.create('Bob Builder', nil) }.to(75 raise_error(TypeAssertionError,76 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got Undef')77 )78 end79 it 'reorders parameters to but the optional parameters last' do80 inst = second.create('Bob Builder', '42 Cool Street', '12345', 'bob@example.com', 23)81 expect(inst.name).to eq('Bob Builder')82 expect(inst.address).to eq('42 Cool Street')83 expect(inst.zipcode).to eq('12345')84 expect(inst.email).to eq('bob@example.com')85 expect(inst.number).to eq(23)86 expect(inst.what).to eql('what is this')87 expect(inst.age).to eql(30)88 expect(inst.another).to be_nil89 end90 end91 context 'the #from_hash class method' do92 it 'has an arity of one' do93 expect(first.method(:from_hash).arity).to eql(1)94 expect(second.method(:from_hash).arity).to eql(1)95 end96 it 'creates an instance of the class' do97 inst = first.from_hash('name' => 'Bob Builder', 'age' => 52)98 expect(inst).to be_a(first)99 expect(inst.name).to eq('Bob Builder')100 expect(inst.age).to eq(52)101 end102 it 'accepts an initializer where optional keys are missing' do103 inst = first.from_hash('name' => 'Bob Builder')104 expect(inst).to be_a(first)105 expect(inst.name).to eq('Bob Builder')106 expect(inst.age).to eq(30)107 end108 it 'does not accept an initializer where optional values are nil and type does not accept nil' do109 expect { first.from_hash('name' => 'Bob Builder', 'age' => nil) }.to(110 raise_error(TypeAssertionError,111 "MyModule::FirstGenerated initializer has wrong type, entry 'age' expects an Integer value, got Undef")112 )113 end114 end115 context 'creates an instance' do116 it 'that the TypeCalculator infers to the Object type' do117 expect(TypeCalculator.infer(first.from_hash('name' => 'Bob Builder'))).to eq(first_type)118 end119 end120 end121 context 'when generating static code' do122 module_def = nil123 before(:each) do124 # Ideally, this would be in a before(:all) but that is impossible since lots of Puppet125 # environment specific settings are configured by the spec_helper in before(:each)126 if module_def.nil?127 first_type = nil128 second_type = nil129 eval_and_collect_notices(source) do |scope, catalog|130 first_type = parser.parse('MyModule::FirstGenerated', scope)131 second_type = parser.parse('MyModule::SecondGenerated', scope)132 loader = Loaders.find_loader(nil)133 Loaders.implementation_registry.register_type_mapping(134 PRuntimeType.new(:ruby, [/^PuppetSpec::RubyGenerator::(\w+)$/, 'MyModule::\1']),135 [/^MyModule::(\w+)$/, 'PuppetSpec::RubyGenerator::\1'], loader)136 module_def = generator.module_definition([first_type, second_type], 'Generated stuff')137 end138 Loaders.clear139 Puppet[:code] = nil140 # Create the actual classes in the PuppetSpec::RubyGenerator module141 Puppet.override(:loaders => Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, []))) do142 eval(module_def, root_binding)143 end144 end145 end146 after(:all) do147 # Don't want generated module to leak outside this test148 PuppetSpec.send(:remove_const, :RubyGenerator)149 end150 it 'the #_ptype class method returns a resolved Type' do151 first_type = PuppetSpec::RubyGenerator::FirstGenerated._ptype152 expect(first_type).to be_a(PObjectType)153 second_type = PuppetSpec::RubyGenerator::SecondGenerated._ptype154 expect(second_type).to be_a(PObjectType)155 expect(second_type.parent).to eql(first_type)156 end157 it 'the #_plocation class method returns a file URI' do158 loc = PuppetSpec::RubyGenerator::SecondGenerated._plocation159 expect(loc).to be_a(URI)160 expect(loc.to_s).to match(/^file:\/.*ruby_generator_spec.rb\?line=\d+$/)161 end162 context 'the #create class method' do163 it 'has an arity that reflects optional arguments' do164 expect(PuppetSpec::RubyGenerator::FirstGenerated.method(:create).arity).to eql(-2)165 expect(PuppetSpec::RubyGenerator::SecondGenerated.method(:create).arity).to eql(-6)166 end167 it 'creates an instance of the class' do168 inst = PuppetSpec::RubyGenerator::FirstGenerated.create('Bob Builder', 52)169 expect(inst).to be_a(PuppetSpec::RubyGenerator::FirstGenerated)170 expect(inst.name).to eq('Bob Builder')171 expect(inst.age).to eq(52)172 end173 it 'will perform type assertion of the arguments' do174 expect { PuppetSpec::RubyGenerator::FirstGenerated.create('Bob Builder', '52') }.to(175 raise_error(TypeAssertionError,176 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got String')177 )178 end179 it 'will not accept nil as given value for an optional parameter that does not accept nil' do180 expect { PuppetSpec::RubyGenerator::FirstGenerated.create('Bob Builder', nil) }.to(181 raise_error(TypeAssertionError,182 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got Undef')183 )184 end185 it 'reorders parameters to but the optional parameters last' do186 inst = PuppetSpec::RubyGenerator::SecondGenerated.create('Bob Builder', '42 Cool Street', '12345', 'bob@example.com', 23)187 expect(inst.name).to eq('Bob Builder')188 expect(inst.address).to eq('42 Cool Street')189 expect(inst.zipcode).to eq('12345')190 expect(inst.email).to eq('bob@example.com')191 expect(inst.number).to eq(23)192 expect(inst.what).to eql('what is this')193 expect(inst.age).to eql(30)194 expect(inst.another).to be_nil195 end196 end197 context 'the #from_hash class method' do198 it 'has an arity of one' do199 expect(PuppetSpec::RubyGenerator::FirstGenerated.method(:from_hash).arity).to eql(1)200 expect(PuppetSpec::RubyGenerator::SecondGenerated.method(:from_hash).arity).to eql(1)201 end202 it 'creates an instance of the class' do203 inst = PuppetSpec::RubyGenerator::FirstGenerated.from_hash('name' => 'Bob Builder', 'age' => 52)204 expect(inst).to be_a(PuppetSpec::RubyGenerator::FirstGenerated)205 expect(inst.name).to eq('Bob Builder')206 expect(inst.age).to eq(52)207 end208 it 'accepts an initializer where optional keys are missing' do209 inst = PuppetSpec::RubyGenerator::FirstGenerated.from_hash('name' => 'Bob Builder')210 expect(inst).to be_a(PuppetSpec::RubyGenerator::FirstGenerated)211 expect(inst.name).to eq('Bob Builder')212 expect(inst.age).to eq(30)213 end214 it 'does not accept an initializer where optional values are nil and type does not accept nil' do215 expect { PuppetSpec::RubyGenerator::FirstGenerated.from_hash('name' => 'Bob Builder', 'age' => nil) }.to(216 raise_error(TypeAssertionError,217 "MyModule::FirstGenerated initializer has wrong type, entry 'age' expects an Integer value, got Undef")218 )219 end220 end221 end222 end223 context 'when generating from TypeSets' do224 def source225 <<-CODE226 type MyModule = TypeSet[{227 pcore_version => '1.0.0',228 version => '1.0.0',229 types => {230 MyInteger => Integer,231 FirstGenerated => Object[{232 attributes => {233 name => String,234 age => { type => Integer, value => 30 },235 what => { type => String, value => 'what is this', kind => constant }236 }237 }],238 SecondGenerated => Object[{239 parent => FirstGenerated,240 attributes => {241 address => String,242 zipcode => String,243 email => String,244 another => { type => Optional[FirstGenerated], value => undef },245 number => MyInteger246 }247 }]248 },249 }]250 type OtherModule = TypeSet[{251 pcore_version => '1.0.0',252 version => '1.0.0',253 types => {254 MyFloat => Float,255 ThirdGenerated => Object[{256 attributes => {257 first => My::FirstGenerated258 }259 }],260 FourthGenerated => Object[{261 parent => My::SecondGenerated,262 attributes => {263 complex => { type => Optional[ThirdGenerated], value => undef },264 n1 => My::MyInteger,265 n2 => MyFloat266 }267 }]268 },269 references => {270 My => { name => 'MyModule', version_range => '1.x' }271 }272 }]273 CODE274 end275 context 'when generating anonymous classes' do276 typeset = nil277 let(:first_type) { typeset['My::FirstGenerated'] }278 let(:second_type) { typeset['My::SecondGenerated'] }279 let(:third_type) { typeset['ThirdGenerated'] }280 let(:fourth_type) { typeset['FourthGenerated'] }281 let(:first) { generator.create_class(first_type) }282 let(:second) { generator.create_class(second_type) }283 let(:third) { generator.create_class(third_type) }284 let(:fourth) { generator.create_class(fourth_type) }285 before(:each) do286 eval_and_collect_notices(source) do |scope, catalog|287 typeset = parser.parse('OtherModule', scope)288 end289 end290 after(:each) { typeset = nil }291 context 'the typeset' do292 it 'produces expected string representation' do293 typeset.to_s == "TypeSet[{"+294 "pcore_version => '1.0.0', "+295 "name_authority => 'http://puppet.com/2016.1/runtime', "+296 "name => 'OtherModule', "+297 "version => '1.0.0', "+298 "types => {"+299 "MyFloat => Float, "+300 "ThirdGenerated => Object[{"+301 "attributes => {"+302 "'first' => MyModule::FirstGenerated}}], "+303 "FourthGenerated => Object[{"+304 "parent => MyModule::SecondGenerated, "+305 "attributes => {"+306 "'complex' => {"+307 "type => Optional[ThirdGenerated], "+308 "value => ?}, "+309 "'n1' => MyModule::MyInteger, "+310 "'n2' => MyFloat}}]}, "+311 "references => [{"+312 "'name' => 'MyModule', "+313 "'alias' => 'My', "+314 "'version_range' => '1.x'}]}]"315 end316 end317 context 'the generated class' do318 it 'inherits the PuppetObject module' do319 expect(first < PuppetObject).to be_truthy320 end321 it 'is the superclass of a generated subclass' do322 expect(second < first).to be_truthy323 end324 end325 context 'the #create class method' do326 it 'has an arity that reflects optional arguments' do327 expect(first.method(:create).arity).to eql(-2)328 expect(second.method(:create).arity).to eql(-6)329 expect(third.method(:create).arity).to eql(1)330 expect(fourth.method(:create).arity).to eql(-8)331 end332 it 'creates an instance of the class' do333 inst = first.create('Bob Builder', 52)334 expect(inst).to be_a(first)335 expect(inst.name).to eq('Bob Builder')336 expect(inst.age).to eq(52)337 end338 it 'will perform type assertion of the arguments' do339 expect { first.create('Bob Builder', '52') }.to(340 raise_error(TypeAssertionError,341 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got String')342 )343 end344 it 'will not accept nil as given value for an optional parameter that does not accept nil' do345 expect { first.create('Bob Builder', nil) }.to(346 raise_error(TypeAssertionError,347 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got Undef')348 )349 end350 it 'reorders parameters to but the optional parameters last' do351 inst = second.create('Bob Builder', '42 Cool Street', '12345', 'bob@example.com', 23)352 expect(inst.name).to eq('Bob Builder')353 expect(inst.address).to eq('42 Cool Street')354 expect(inst.zipcode).to eq('12345')355 expect(inst.email).to eq('bob@example.com')356 expect(inst.number).to eq(23)357 expect(inst.what).to eql('what is this')358 expect(inst.age).to eql(30)359 expect(inst.another).to be_nil360 end361 end362 context 'the #from_hash class method' do363 it 'has an arity of one' do364 expect(first.method(:from_hash).arity).to eql(1)365 expect(second.method(:from_hash).arity).to eql(1)366 end367 it 'creates an instance of the class' do368 inst = first.from_hash('name' => 'Bob Builder', 'age' => 52)369 expect(inst).to be_a(first)370 expect(inst.name).to eq('Bob Builder')371 expect(inst.age).to eq(52)372 end373 it 'accepts an initializer where optional keys are missing' do374 inst = first.from_hash('name' => 'Bob Builder')375 expect(inst).to be_a(first)376 expect(inst.name).to eq('Bob Builder')377 expect(inst.age).to eq(30)378 end379 it 'does not accept an initializer where optional values are nil and type does not accept nil' do380 expect { first.from_hash('name' => 'Bob Builder', 'age' => nil) }.to(381 raise_error(TypeAssertionError,382 "MyModule::FirstGenerated initializer has wrong type, entry 'age' expects an Integer value, got Undef")383 )384 end385 end386 context 'creates an instance' do387 it 'that the TypeCalculator infers to the Object type' do388 expect(TypeCalculator.infer(first.from_hash('name' => 'Bob Builder'))).to eq(first_type)389 end390 end391 end392 context 'when generating static code' do393 module_def = nil394 module_def2 = nil395 before(:each) do396 # Ideally, this would be in a before(:all) but that is impossible since lots of Puppet397 # environment specific settings are configured by the spec_helper in before(:each)398 if module_def.nil?399 typeset = nil400 eval_and_collect_notices(source) do |scope, catalog|401 typeset1 = parser.parse('MyModule', scope)402 typeset2 = parser.parse('OtherModule', scope)403 loader = Loaders.find_loader(nil)404 Loaders.implementation_registry.register_type_mapping(405 PRuntimeType.new(:ruby, [/^PuppetSpec::RubyGenerator::My::(\w+)$/, 'MyModule::\1']),406 [/^MyModule::(\w+)$/, 'PuppetSpec::RubyGenerator::My::\1'], loader)407 Loaders.implementation_registry.register_type_mapping(408 PRuntimeType.new(:ruby, [/^PuppetSpec::RubyGenerator::Other::(\w+)$/, 'OtherModule::\1']),409 [/^OtherModule::(\w+)$/, 'PuppetSpec::RubyGenerator::Other::\1'], loader)410 module_def = generator.module_definition_from_typeset(typeset1)411 module_def2 = generator.module_definition_from_typeset(typeset2)412 end413 Loaders.clear414 Puppet[:code] = nil415 # Create the actual classes in the PuppetSpec::RubyGenerator module416 Puppet.override(:loaders => Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, []))) do417 eval(module_def, root_binding)418 eval(module_def2, root_binding)419 end420 end421 end422 after(:all) do423 # Don't want generated module to leak outside this test424 PuppetSpec.send(:remove_const, :RubyGenerator)425 end426 it 'the #_ptype class method returns a resolved Type' do427 first_type = PuppetSpec::RubyGenerator::My::FirstGenerated._ptype428 expect(first_type).to be_a(PObjectType)429 second_type = PuppetSpec::RubyGenerator::My::SecondGenerated._ptype430 expect(second_type).to be_a(PObjectType)431 expect(second_type.parent).to eql(first_type)432 end433 it 'the #_plocation class method returns a file URI' do434 loc = PuppetSpec::RubyGenerator::My::SecondGenerated._plocation435 expect(loc).to be_a(URI)436 expect(loc.to_s).to match(/^file:\/.*ruby_generator_spec.rb\?line=\d+$/)437 end438 context 'the #create class method' do439 it 'has an arity that reflects optional arguments' do440 expect(PuppetSpec::RubyGenerator::My::FirstGenerated.method(:create).arity).to eql(-2)441 expect(PuppetSpec::RubyGenerator::My::SecondGenerated.method(:create).arity).to eql(-6)442 end443 it 'creates an instance of the class' do444 inst = PuppetSpec::RubyGenerator::My::FirstGenerated.create('Bob Builder', 52)445 expect(inst).to be_a(PuppetSpec::RubyGenerator::My::FirstGenerated)446 expect(inst.name).to eq('Bob Builder')447 expect(inst.age).to eq(52)448 end449 it 'will perform type assertion of the arguments' do450 expect { PuppetSpec::RubyGenerator::My::FirstGenerated.create('Bob Builder', '52') }.to(451 raise_error(TypeAssertionError,452 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got String')453 )454 end455 it 'will not accept nil as given value for an optional parameter that does not accept nil' do456 expect { PuppetSpec::RubyGenerator::My::FirstGenerated.create('Bob Builder', nil) }.to(457 raise_error(TypeAssertionError,458 'MyModule::FirstGenerated[age] has wrong type, expects an Integer value, got Undef')459 )460 end461 it 'reorders parameters to but the optional parameters last' do462 inst = PuppetSpec::RubyGenerator::My::SecondGenerated.create('Bob Builder', '42 Cool Street', '12345', 'bob@example.com', 23)463 expect(inst.name).to eq('Bob Builder')464 expect(inst.address).to eq('42 Cool Street')465 expect(inst.zipcode).to eq('12345')466 expect(inst.email).to eq('bob@example.com')467 expect(inst.number).to eq(23)468 expect(inst.what).to eql('what is this')469 expect(inst.age).to eql(30)470 expect(inst.another).to be_nil471 end472 end473 context 'the #from_hash class method' do474 it 'has an arity of one' do475 expect(PuppetSpec::RubyGenerator::My::FirstGenerated.method(:from_hash).arity).to eql(1)476 expect(PuppetSpec::RubyGenerator::My::SecondGenerated.method(:from_hash).arity).to eql(1)477 end478 it 'creates an instance of the class' do479 inst = PuppetSpec::RubyGenerator::My::FirstGenerated.from_hash('name' => 'Bob Builder', 'age' => 52)480 expect(inst).to be_a(PuppetSpec::RubyGenerator::My::FirstGenerated)481 expect(inst.name).to eq('Bob Builder')482 expect(inst.age).to eq(52)483 end484 it 'accepts an initializer where optional keys are missing' do485 inst = PuppetSpec::RubyGenerator::My::FirstGenerated.from_hash('name' => 'Bob Builder')486 expect(inst).to be_a(PuppetSpec::RubyGenerator::My::FirstGenerated)487 expect(inst.name).to eq('Bob Builder')488 expect(inst.age).to eq(30)489 end490 it 'does not accept an initializer where optional values are nil and type does not accept nil' do491 expect { PuppetSpec::RubyGenerator::My::FirstGenerated.from_hash('name' => 'Bob Builder', 'age' => nil) }.to(492 raise_error(TypeAssertionError,493 "MyModule::FirstGenerated initializer has wrong type, entry 'age' expects an Integer value, got Undef")494 )495 end496 end497 end498 end499end500end501end...
test_runtime_package.rb
Source:test_runtime_package.rb
...155 db.repository.modules = ['MyModule']156 db.repository.table_map = {'MyModule' => []}157 db.search_dirs = [create_dir('databases')]158 end159 Dbt::Config.index_file_name = 'myindex.txt'160 output_dir = create_dir('pkg/out')161 Dbt.runtime.package_database_data(database, output_dir)162 assert_file_exist("#{output_dir}/MyModule/base1.sql")163 assert_file_exist("#{output_dir}/MyModule/base2.sql")164 assert_file_exist("#{output_dir}/MyModule/base3.sql")165 assert_file_exist("#{output_dir}/MyModule/myindex.txt")166 index = IO.readlines("#{output_dir}/MyModule/myindex.txt")167 assert_equal index.size, 3168 assert_equal index[0].strip, 'base1.sql'169 assert_equal index[1].strip, 'base2.sql'170 assert_equal index[2].strip, 'base3.sql'171 end172 def test_ordering_in_index_with_partial_index_supplied173 Dbt::Config.index_file_name = 'myindex.txt'174 create_file('databases/MyModule/myindex.txt', "base3.sql\nbase2.sql\n")175 create_file('databases/MyModule/base1.sql', '')176 create_file('databases/MyModule/base2.sql', '')177 create_file('databases/MyModule/base3.sql', '')178 create_file('databases/MyModule/base4.sql', '')179 database = Dbt.add_database(:default) do |db|180 db.rake_integration = false181 db.repository.modules = ['MyModule']182 db.repository.table_map = {'MyModule' => []}183 db.search_dirs = [create_dir('databases')]184 end185 output_dir = create_dir('pkg/out')186 Dbt.runtime.package_database_data(database, output_dir)187 assert_file_exist("#{output_dir}/MyModule/base1.sql")188 assert_file_exist("#{output_dir}/MyModule/base2.sql")189 assert_file_exist("#{output_dir}/MyModule/base3.sql")190 assert_file_exist("#{output_dir}/MyModule/base4.sql")191 assert_file_exist("#{output_dir}/MyModule/myindex.txt")192 index = IO.readlines("#{output_dir}/MyModule/myindex.txt")193 assert_equal index.size, 4194 assert_equal index[0].strip, 'base3.sql'195 assert_equal index[1].strip, 'base2.sql'196 assert_equal index[2].strip, 'base1.sql'197 assert_equal index[3].strip, 'base4.sql'198 end199 def test_ordering_in_index_with_full_index_supplied200 Dbt::Config.index_file_name = 'myindex.txt'201 create_file('databases/MyModule/myindex.txt', "base3.sql\nbase1.sql\nbase2.sql\n")202 create_file('databases/MyModule/base1.sql', '')203 create_file('databases/MyModule/base2.sql', '')204 create_file('databases/MyModule/base3.sql', '')205 database = Dbt.add_database(:default) do |db|206 db.rake_integration = false207 db.repository.modules = ['MyModule']208 db.repository.table_map = {'MyModule' => []}209 db.search_dirs = [create_dir('databases')]210 end211 output_dir = create_dir('pkg/out')212 Dbt.runtime.package_database_data(database, output_dir)213 assert_file_exist("#{output_dir}/MyModule/base1.sql")214 assert_file_exist("#{output_dir}/MyModule/base2.sql")215 assert_file_exist("#{output_dir}/MyModule/base3.sql")216 assert_file_exist("#{output_dir}/MyModule/myindex.txt")217 index = IO.readlines("#{output_dir}/MyModule/myindex.txt")218 assert_equal index.size, 3219 assert_equal index[0].strip, 'base3.sql'220 assert_equal index[1].strip, 'base1.sql'221 assert_equal index[2].strip, 'base2.sql'222 end223 def test_data_sets_copied224 db_scripts = create_dir('databases/generated')225 create_file('databases/generated/MyModule/zang/bing/foo.yml', '')226 database = Dbt.add_database(:default) do |db|227 db.rake_integration = false228 db.repository.modules = ['MyModule']229 db.repository.table_map = {'MyModule' => ['foo', 'bar', 'baz']}230 db.search_dirs = [db_scripts]231 db.datasets = ['bing']232 end233 Dbt::Config.default_datasets_dir_name = 'zang'234 output_dir = create_dir('pkg/out')235 Dbt.runtime.package_database_data(database, output_dir)236 assert_file_exist("#{output_dir}/MyModule/zang/bing/foo.yml")237 end238 def test_imports_copied239 db_scripts = create_dir('databases/generated')240 create_file('databases/generated/MyModule/import1/foo.yml', '')241 database = Dbt.add_database(:default) do |db|242 db.rake_integration = false243 db.repository.modules = ['MyModule']244 db.repository.table_map = {'MyModule' => ['foo', 'bar', 'baz']}245 db.search_dirs = [db_scripts]246 db.add_import(:default, {})247 end...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!