Port mysql tests
This commit is contained in:
parent
562e722541
commit
5bde9392c7
20 changed files with 181 additions and 0 deletions
|
@ -15,6 +15,8 @@ class MySqlExecutor extends QueryExecutor {
|
|||
|
||||
MySqlExecutor(this._connection, {this.logger});
|
||||
|
||||
Future<void> close() => _connection.close();
|
||||
|
||||
@override
|
||||
Future<List<List>> query(
|
||||
String tableName, String query, Map<String, dynamic> substitutionValues,
|
||||
|
|
|
@ -14,5 +14,7 @@ dev_dependencies:
|
|||
angel_migration: ^2.0.0-alpha
|
||||
angel_orm_generator:
|
||||
path: ../angel_orm_generator
|
||||
angel_orm_test:
|
||||
path: ../angel_orm_test
|
||||
build_runner: ^1.0.0
|
||||
test: ^1.0.0
|
31
angel_orm_mysql/test/all_test.dart
Normal file
31
angel_orm_mysql/test/all_test.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
import 'package:angel_orm_test/angel_orm_test.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
Logger.root.onRecord.listen((rec) {
|
||||
print(rec);
|
||||
if (rec.error != null) print(rec.error);
|
||||
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||
});
|
||||
|
||||
group('postgresql', () {
|
||||
group('belongsTo',
|
||||
() => belongsToTests(my(['author', 'book']), close: closeMy));
|
||||
group(
|
||||
'edgeCase',
|
||||
() => edgeCaseTests(my(['unorthodox', 'weird_join', 'song', 'numba']),
|
||||
close: closeMy));
|
||||
group('enumAndNested',
|
||||
() => enumAndNestedTests(my(['has_car']), close: closeMy));
|
||||
group('hasMany', () => hasManyTests(my(['tree', 'fruit']), close: closeMy));
|
||||
group('hasMap', () => hasMapTests(my(['has_map']), close: closeMy));
|
||||
group('hasOne', () => hasOneTests(my(['leg', 'foot']), close: closeMy));
|
||||
group(
|
||||
'manyToMany',
|
||||
() =>
|
||||
manyToManyTests(my(['user', 'role', 'user_role']), close: closeMy));
|
||||
group('standalone', () => standaloneTests(my(['car']), close: closeMy));
|
||||
});
|
||||
}
|
28
angel_orm_mysql/test/common.dart
Normal file
28
angel_orm_mysql/test/common.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_orm_mysql/angel_orm_mysql.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:sqljocky5/sqljocky.dart';
|
||||
|
||||
FutureOr<QueryExecutor> Function() my(Iterable<String> schemas) {
|
||||
return () => connectToMySql(schemas);
|
||||
}
|
||||
|
||||
Future<void> closeMy(QueryExecutor executor) =>
|
||||
(executor as MySqlExecutor).close();
|
||||
|
||||
Future<MySqlExecutor> connectToMySql(Iterable<String> schemas) async {
|
||||
var settings = ConnectionSettings(
|
||||
db: 'angel_orm_test',
|
||||
user: Platform.environment['MYSQL_USERNAME'] ?? 'angel_orm_test',
|
||||
password: Platform.environment['MYSQL_PASSWORD'] ?? 'angel_orm_test');
|
||||
var connection = await MySqlConnection.connect(settings);
|
||||
var logger = Logger('angel_orm_mysql');
|
||||
|
||||
for (var s in schemas)
|
||||
await connection
|
||||
.execute(await new File('test/migrations/$s.sql').readAsString());
|
||||
|
||||
return MySqlExecutor(connection, logger: logger);
|
||||
}
|
6
angel_orm_mysql/test/migrations/author.sql
Normal file
6
angel_orm_mysql/test/migrations/author.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TEMPORARY TABLE "authors" (
|
||||
id serial PRIMARY KEY,
|
||||
name varchar(255) UNIQUE NOT NULL,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
8
angel_orm_mysql/test/migrations/book.sql
Normal file
8
angel_orm_mysql/test/migrations/book.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TEMPORARY TABLE "books" (
|
||||
id serial PRIMARY KEY,
|
||||
author_id int NOT NULL,
|
||||
partner_author_id int,
|
||||
name varchar(255),
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
9
angel_orm_mysql/test/migrations/car.sql
Normal file
9
angel_orm_mysql/test/migrations/car.sql
Normal file
|
@ -0,0 +1,9 @@
|
|||
CREATE TEMPORARY TABLE "cars" (
|
||||
id serial PRIMARY KEY,
|
||||
make varchar(255) NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
family_friendly BOOLEAN NOT NULL,
|
||||
recalled_at timestamp,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
7
angel_orm_mysql/test/migrations/foot.sql
Normal file
7
angel_orm_mysql/test/migrations/foot.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TEMPORARY TABLE "feet" (
|
||||
id serial PRIMARY KEY,
|
||||
leg_id int NOT NULL,
|
||||
n_toes int NOT NULL,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
8
angel_orm_mysql/test/migrations/fruit.sql
Normal file
8
angel_orm_mysql/test/migrations/fruit.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TEMPORARY TABLE "fruits" (
|
||||
"id" serial,
|
||||
"tree_id" int,
|
||||
"common_name" varchar,
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp,
|
||||
PRIMARY KEY(id)
|
||||
);
|
6
angel_orm_mysql/test/migrations/has_car.sql
Normal file
6
angel_orm_mysql/test/migrations/has_car.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TEMPORARY TABLE "has_cars" (
|
||||
id serial PRIMARY KEY,
|
||||
type int not null,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
7
angel_orm_mysql/test/migrations/has_map.sql
Normal file
7
angel_orm_mysql/test/migrations/has_map.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TEMPORARY TABLE "has_maps" (
|
||||
id serial PRIMARY KEY,
|
||||
value jsonb not null,
|
||||
list jsonb not null,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
6
angel_orm_mysql/test/migrations/leg.sql
Normal file
6
angel_orm_mysql/test/migrations/leg.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TEMPORARY TABLE "legs" (
|
||||
id serial PRIMARY KEY,
|
||||
name varchar(255) NOT NULL,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
7
angel_orm_mysql/test/migrations/numba.sql
Normal file
7
angel_orm_mysql/test/migrations/numba.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TEMPORARY TABLE "numbas" (
|
||||
"i" int,
|
||||
"parent" int references weird_joins(id),
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
PRIMARY KEY(i)
|
||||
);
|
6
angel_orm_mysql/test/migrations/role.sql
Normal file
6
angel_orm_mysql/test/migrations/role.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TEMPORARY TABLE "roles" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"name" varchar(255),
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp
|
||||
);
|
8
angel_orm_mysql/test/migrations/song.sql
Normal file
8
angel_orm_mysql/test/migrations/song.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TEMPORARY TABLE "songs" (
|
||||
"id" serial,
|
||||
"weird_join_id" int references weird_joins(id),
|
||||
"title" varchar(255),
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
PRIMARY KEY(id)
|
||||
);
|
8
angel_orm_mysql/test/migrations/tree.sql
Normal file
8
angel_orm_mysql/test/migrations/tree.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TEMPORARY TABLE "trees" (
|
||||
"id" serial,
|
||||
"rings" smallint UNIQUE,
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp,
|
||||
UNIQUE(rings),
|
||||
PRIMARY KEY(id)
|
||||
);
|
4
angel_orm_mysql/test/migrations/unorthodox.sql
Normal file
4
angel_orm_mysql/test/migrations/unorthodox.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
CREATE TEMPORARY TABLE "unorthodoxes" (
|
||||
"name" varchar(255),
|
||||
PRIMARY KEY(name)
|
||||
);
|
8
angel_orm_mysql/test/migrations/user.sql
Normal file
8
angel_orm_mysql/test/migrations/user.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TEMPORARY TABLE "users" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"username" varchar(255),
|
||||
"password" varchar(255),
|
||||
"email" varchar(255),
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp
|
||||
);
|
7
angel_orm_mysql/test/migrations/user_role.sql
Normal file
7
angel_orm_mysql/test/migrations/user_role.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TEMPORARY TABLE "role_users" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"user_id" int NOT NULL,
|
||||
"role_id" int NOT NULL,
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp
|
||||
);
|
13
angel_orm_mysql/test/migrations/weird_join.sql
Normal file
13
angel_orm_mysql/test/migrations/weird_join.sql
Normal file
|
@ -0,0 +1,13 @@
|
|||
CREATE TEMPORARY TABLE "weird_joins" (
|
||||
"id" serial,
|
||||
"join_name" varchar(255) references unorthodoxes(name),
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
CREATE TEMPORARY TABLE "foos" (
|
||||
"bar" varchar(255),
|
||||
PRIMARY KEY(bar)
|
||||
);
|
||||
CREATE TEMPORARY TABLE "foo_pivots" (
|
||||
"weird_join_id" int references weird_joins(id),
|
||||
"foo_bar" varchar(255) references foos(bar)
|
||||
);
|
Loading…
Reference in a new issue