sqlite3_test 0.1.0 copy "sqlite3_test: ^0.1.0" to clipboard
sqlite3_test: ^0.1.0 copied to clipboard

Integration of fake clocks and other test utilities for SQLite databases.

example/sqlite3_test_example.dart

import 'package:fake_async/fake_async.dart';
import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite3_test/sqlite3_test.dart';
import 'package:file/local.dart';
import 'package:test/test.dart';

void main() {
  late TestSqliteFileSystem vfs;

  setUpAll(() {
    vfs = TestSqliteFileSystem(fs: const LocalFileSystem());
    sqlite3.registerVirtualFileSystem(vfs);
  });
  tearDownAll(() => sqlite3.unregisterVirtualFileSystem(vfs));

  test('my test depending on database time', () {
    final database = sqlite3.openInMemory(vfs: vfs.name);
    addTearDown(database.dispose);

    // The VFS uses package:clock to get the current time, which can be
    // overridden for tests:
    final moonLanding = DateTime.utc(1969, 7, 20, 20, 18, 04);
    FakeAsync(initialTime: moonLanding).run((_) {
      final row = database.select('SELECT unixepoch(current_timestamp)').first;

      expect(row.columnAt(0), -14182916);
    });
  });
}
0
likes
160
points
57
downloads

Publisher

verified publishersimonbinder.eu

Weekly Downloads

Integration of fake clocks and other test utilities for SQLite databases.

Homepage
Repository (GitHub)
View/report issues

Topics

#database #sqlite

Documentation

API reference

License

MIT (license)

Dependencies

clock, file, sqlite3

More

Packages that depend on sqlite3_test