enable unit test

This commit is contained in:
Andika Tanuwijaya
2025-07-02 20:20:37 +07:00
parent 470aed41e9
commit 2eb301f62a
3 changed files with 47 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
library;
export 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
export 'src/client.dart';

View File

@@ -1 +1,2 @@
/target
/test_build

View File

@@ -0,0 +1,44 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:turso_dart/src/rust/frb_generated.dart';
import 'package:turso_dart/turso_dart.dart';
void main() async {
setUpAll(() async {
final lib = await loadExternalLibrary(
ExternalLibraryLoaderConfig(
stem: "turso_dart",
ioDirectory: "rust/test_build/debug/",
webPrefix: null,
),
);
await RustLib.init(externalLibrary: lib);
});
test('should be able to perform queries', () async {
final client = TursoClient.memory();
await client.connect();
await client.execute(
"create table if not exists tasks (id integer primary key, title text, description text, completed integer)",
);
final rowsAffected = await client.execute(
"insert into tasks (title, description, completed) values (?, ?, ?)",
positional: ["title", "description", 0],
);
expect(rowsAffected, equals(1));
final result = await client.query("select * from tasks");
expect(
result,
equals([
{
"id": 1,
"title": "title",
"description": "description",
"completed": 0,
},
]),
);
});
}