|
| 1 | +use Mojo::Base -strict; |
| 2 | + |
| 3 | +use Test::More; |
| 4 | +use Test::Mojo; |
| 5 | +use CellBIS::SQL::Abstract::Test; |
| 6 | + |
| 7 | +plan skip_all => |
| 8 | + 'set TEST_ONLINE_mariadb and TEST_ONLINE_pg to enable this test' |
| 9 | + unless $ENV{TEST_ONLINE_mariadb} && $ENV{TEST_ONLINE_pg}; |
| 10 | + |
| 11 | +BEGIN { |
| 12 | + $ENV{PLACK_ENV} = undef; |
| 13 | + $ENV{MOJO_MODE} = 'development'; |
| 14 | + $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll'; |
| 15 | +} |
| 16 | + |
| 17 | +use Mojo::File 'curfile'; |
| 18 | +use lib curfile->sibling('lib')->to_string; |
| 19 | + |
| 20 | +my ($test, $db, $backend); |
| 21 | + |
| 22 | +# Initialization for SQLite |
| 23 | +$test = CellBIS::SQL::Abstract::Test->new(table => 'users'); |
| 24 | +unless (-d $test->dir) { mkdir $test->dir } |
| 25 | + |
| 26 | +$backend = $test->backend; |
| 27 | +$db = $backend->db; |
| 28 | + |
| 29 | +note 'sqlite - connection test'; |
| 30 | +ok $db->ping, 'connected'; |
| 31 | + |
| 32 | +note 'sqlite - for table users'; |
| 33 | +is $test->check_table->{result} => undef, 'no table'; |
| 34 | +is $test->create_table->{code} => 200, 'success create table'; |
| 35 | +is $test->empty_table->{code} => 200, 'empty table'; |
| 36 | +is $test->drop_table->{code} => 200, 'drop table'; |
| 37 | + |
| 38 | +note 'sqlite - for table roles'; |
| 39 | +$test->table('roles'); |
| 40 | +is $test->check_table->{result} => undef, 'no table'; |
| 41 | +is $test->create_table->{code} => 200, 'success create table'; |
| 42 | +is $test->empty_table->{code} => 200, 'empty table'; |
| 43 | +is $test->drop_table->{code} => 200, 'drop table'; |
| 44 | + |
| 45 | +note 'sqlite - for relation table'; |
| 46 | +is $test->check_table->{result} => undef, 'no table roles'; |
| 47 | +is $test->create_table->{code} => 200, 'success create table roles'; |
| 48 | +$test->table('users'); |
| 49 | +is $test->check_table->{result} => undef, 'no table users'; |
| 50 | +is $test->create_table_with_fk->{code} => 200, 'success create table users'; |
| 51 | + |
| 52 | +$test->dir->remove_tree; |
| 53 | + |
| 54 | +# Switch to MariaDB |
| 55 | +$test->dsn($ENV{TEST_ONLINE_mariadb}); |
| 56 | +$test->change_dbms('mariadb'); |
| 57 | +$backend = $test->backend; |
| 58 | +$db = $backend->db; |
| 59 | + |
| 60 | +note 'mariadb - connection test'; |
| 61 | +ok $db->ping, 'connected'; |
| 62 | + |
| 63 | +note 'mariadb - for table users'; |
| 64 | +$test->table('users'); |
| 65 | +is $test->check_table->{result} => undef, 'mariadb - no table'; |
| 66 | +is $test->create_table->{code} => 200, 'mariadb - success create table'; |
| 67 | +is $test->empty_table->{code} => 200, 'mariadb - empty table'; |
| 68 | +is $test->drop_table->{code} => 200, 'mariadb - drop table'; |
| 69 | + |
| 70 | +note 'mariadb - for table roles'; |
| 71 | +$test->table('roles'); |
| 72 | +is $test->check_table->{result} => undef, 'mariadb - no table'; |
| 73 | +is $test->create_table->{code} => 200, 'mariadb - success create table'; |
| 74 | +is $test->empty_table->{code} => 200, 'mariadb - empty table'; |
| 75 | +is $test->drop_table->{code} => 200, 'mariadb - drop table'; |
| 76 | + |
| 77 | +note 'mariadb - for relation table'; |
| 78 | +is $test->check_table->{result} => undef, 'mariadb - no table roles'; |
| 79 | +is $test->create_table->{code} => 200, 'mariadb - success create table roles'; |
| 80 | +$test->table('users'); |
| 81 | +is $test->check_table->{result} => undef, 'mariadb - no table users'; |
| 82 | +is $test->create_table_with_fk->{code} => 200, |
| 83 | + 'mariadb - success create table users'; |
| 84 | +is $test->drop_table->{code} => 200, 'mariadb - drop table'; |
| 85 | +$test->table('roles'); |
| 86 | +is $test->drop_table->{code} => 200, 'mariadb - drop table'; |
| 87 | + |
| 88 | +# switch to PostgreSQL |
| 89 | +$test->dsn($ENV{TEST_ONLINE_pg}); |
| 90 | +$test->change_dbms('pg'); |
| 91 | +$backend = $test->backend; |
| 92 | +$db = $backend->db; |
| 93 | + |
| 94 | +note 'pg - connection test'; |
| 95 | +ok $db->ping, 'connected'; |
| 96 | + |
| 97 | +note 'pg - for table users'; |
| 98 | +$test->table('users'); |
| 99 | +is $test->check_table->{result} => undef, 'pg - no table'; |
| 100 | +is $test->create_table->{code} => 200, 'pg - success create table'; |
| 101 | +is $test->empty_table->{code} => 200, 'pg - empty table'; |
| 102 | +is $test->drop_table->{code} => 200, 'pg - drop table'; |
| 103 | + |
| 104 | +note 'pg - for table roles'; |
| 105 | +$test->table('roles'); |
| 106 | +is $test->check_table->{result} => undef, 'pg - no table'; |
| 107 | +is $test->create_table->{code} => 200, 'pg - success create table'; |
| 108 | +is $test->empty_table->{code} => 200, 'pg - empty table'; |
| 109 | +is $test->drop_table->{code} => 200, 'pg - drop table'; |
| 110 | + |
| 111 | +note 'pg - for relation table'; |
| 112 | +is $test->check_table->{result} => undef, 'pg - no table roles'; |
| 113 | +is $test->create_table->{code} => 200, 'pg - success create table roles'; |
| 114 | +$test->table('users'); |
| 115 | +is $test->check_table->{result} => undef, 'pg - no table users'; |
| 116 | +is $test->create_table_with_fk->{code} => 200, |
| 117 | + 'pg - success create table users'; |
| 118 | +is $test->drop_table->{code} => 200, 'pg - drop table'; |
| 119 | +$test->table('roles'); |
| 120 | +is $test->drop_table->{code} => 200, 'pg - drop table'; |
| 121 | + |
| 122 | +# Switch back to SQLite |
| 123 | +$test->change_dbms('sqlite'); |
| 124 | +unless (-d $test->dir) { mkdir $test->dir } |
| 125 | +$backend = $test->backend; |
| 126 | +$db = $backend->db; |
| 127 | + |
| 128 | +note 'back to sqlite - connection test'; |
| 129 | +ok $db->ping, 'connected'; |
| 130 | + |
| 131 | +note 'back to sqlite - for table users'; |
| 132 | +$test->table('users'); |
| 133 | +is $test->check_table->{result} => undef, 'back to sqlite - no table'; |
| 134 | +is $test->create_table->{code} => 200, 'back to sqlite - success create table'; |
| 135 | +is $test->empty_table->{code} => 200, 'back to sqlite - empty table'; |
| 136 | +is $test->drop_table->{code} => 200, 'back to sqlite - drop table'; |
| 137 | + |
| 138 | +$test->dir->remove_tree; |
| 139 | + |
| 140 | +done_testing(); |
0 commit comments