1import ./make-test-python.nix (
2 { pkgs, lib, ... }:
3
4 /*
5 This test suite replaces the typical pytestCheckHook function in
6 sqlite3-to-mysql due to the need of a running mysql instance.
7 */
8
9 {
10 name = "sqlite3-to-mysql";
11 meta.maintainers = with lib.maintainers; [ gador ];
12
13 nodes.machine =
14 { pkgs, ... }:
15 {
16 environment.systemPackages = with pkgs; [
17 sqlite3-to-mysql
18 # create one coherent python environment
19 (python3.withPackages (
20 ps:
21 sqlite3-to-mysql.propagatedBuildInputs
22 ++ [
23 python3Packages.pytest
24 python3Packages.pytest-mock
25 python3Packages.pytest-timeout
26 python3Packages.factory-boy
27 python3Packages.docker # only needed so import does not fail
28 sqlite3-to-mysql
29 ]
30 ))
31 ];
32 services.mysql = {
33 package = pkgs.mariadb;
34 enable = true;
35 # from https://github.com/techouse/sqlite3-to-mysql/blob/master/tests/conftest.py
36 # and https://github.com/techouse/sqlite3-to-mysql/blob/master/.github/workflows/test.yml
37 initialScript = pkgs.writeText "mysql-init.sql" ''
38 create database test_db DEFAULT CHARACTER SET utf8mb4;
39 create user tester identified by 'testpass';
40 grant all on test_db.* to tester;
41 create user tester@localhost identified by 'testpass';
42 grant all on test_db.* to tester@localhost;
43 '';
44 settings = {
45 mysqld = {
46 character-set-server = "utf8mb4";
47 collation-server = "utf8mb4_unicode_ci";
48 log_warnings = 1;
49 };
50 };
51 };
52 };
53
54 testScript = ''
55 machine.wait_for_unit("mysql")
56
57 machine.succeed(
58 "sqlite3mysql --version | grep ${pkgs.sqlite3-to-mysql.version}"
59 )
60
61 # invalid_database_name: assert '1045 (28000): Access denied' in "1044 (42000): Access denied [...]
62 # invalid_database_user: does not return non-zero exit for some reason
63 # test_version: has problems importing sqlite3_to_mysql and determining the version
64 machine.succeed(
65 "cd ${pkgs.sqlite3-to-mysql.src} \
66 && pytest -v --no-docker -k \"not test_invalid_database_name and not test_invalid_database_user and not test_version\""
67 )
68 '';
69 }
70)