diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c7aa9ed78ba4..dd5acbda39a8 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -581,6 +581,7 @@ in { sourcehut = handleTest ./sourcehut.nix {}; spacecookie = handleTest ./spacecookie.nix {}; spark = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./spark {}; + sqlite3-to-mysql = handleTest ./sqlite3-to-mysql.nix {}; sslh = handleTest ./sslh.nix {}; sssd = handleTestOn ["x86_64-linux"] ./sssd.nix {}; sssd-ldap = handleTestOn ["x86_64-linux"] ./sssd-ldap.nix {}; diff --git a/nixos/tests/sqlite3-to-mysql.nix b/nixos/tests/sqlite3-to-mysql.nix new file mode 100644 index 000000000000..029058187df3 --- /dev/null +++ b/nixos/tests/sqlite3-to-mysql.nix @@ -0,0 +1,65 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: + +/* + This test suite replaces the typical pytestCheckHook function in + sqlite3-to-mysql due to the need of a running mysql instance. +*/ + +{ + name = "sqlite3-to-mysql"; + meta.maintainers = with lib.maintainers; [ gador ]; + + nodes.machine = { pkgs, ... }: { + environment.systemPackages = with pkgs; [ + sqlite3-to-mysql + # create one coherent python environment + (python3.withPackages + (ps: sqlite3-to-mysql.propagatedBuildInputs ++ + [ + python3Packages.pytest + python3Packages.pytest-mock + python3Packages.pytest-timeout + python3Packages.factory_boy + python3Packages.docker # only needed so import does not fail + sqlite3-to-mysql + ]) + ) + ]; + services.mysql = { + package = pkgs.mariadb; + enable = true; + # from https://github.com/techouse/sqlite3-to-mysql/blob/master/tests/conftest.py + # and https://github.com/techouse/sqlite3-to-mysql/blob/master/.github/workflows/test.yml + initialScript = pkgs.writeText "mysql-init.sql" '' + create database test_db DEFAULT CHARACTER SET utf8mb4; + create user tester identified by 'testpass'; + grant all on test_db.* to tester; + create user tester@localhost identified by 'testpass'; + grant all on test_db.* to tester@localhost; + ''; + settings = { + mysqld = { + character-set-server = "utf8mb4"; + collation-server = "utf8mb4_unicode_ci"; + log_warnings = 1; + }; + }; + }; + }; + + testScript = '' + machine.wait_for_unit("mysql") + + machine.succeed( + "sqlite3mysql --version | grep ${pkgs.sqlite3-to-mysql.version}" + ) + + # invalid_database_name: assert '1045 (28000): Access denied' in "1044 (42000): Access denied [...] + # invalid_database_user: does not return non-zero exit for some reason + # test_version: has problems importing sqlite3_to_mysql and determining the version + machine.succeed( + "cd ${pkgs.sqlite3-to-mysql.src} \ + && pytest -v --no-docker -k \"not test_invalid_database_name and not test_invalid_database_user and not test_version\"" + ) + ''; +}) diff --git a/pkgs/tools/misc/sqlite3-to-mysql/default.nix b/pkgs/tools/misc/sqlite3-to-mysql/default.nix new file mode 100644 index 000000000000..cb16a93dd207 --- /dev/null +++ b/pkgs/tools/misc/sqlite3-to-mysql/default.nix @@ -0,0 +1,50 @@ +{ lib +, fetchFromGitHub +, python3Packages +, nixosTests +}: + +python3Packages.buildPythonApplication rec { + pname = "sqlite3-to-mysql"; + version = "1.4.16"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "techouse"; + repo = pname; + rev = "refs/tags/v${version}"; + hash = "sha256-Fxt1zOyEnBuMkCLCABfijo0514NbFocdsjrQU43qVhY="; + }; + + propagatedBuildInputs = with python3Packages; [ + click + mysql-connector + pytimeparse + pymysql + pymysqlsa + six + simplejson + sqlalchemy + sqlalchemy-utils + tqdm + tabulate + unidecode + packaging + ]; + + # tests require a mysql server instance + doCheck = false; + + # run package tests as a seperate nixos test + passthru.tests = { + nixosTest = nixosTests.sqlite3-to-mysql; + }; + + + meta = with lib; { + description = "A simple Python tool to transfer data from SQLite 3 to MySQL"; + homepage = "https://github.com/techouse/sqlite3-to-mysql"; + license = licenses.mit; + maintainers = with maintainers; [ gador ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9501acb83143..902a19e99817 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11584,6 +11584,8 @@ with pkgs; sqliteman = callPackage ../applications/misc/sqliteman { }; + sqlite3-to-mysql = callPackage ../tools/misc/sqlite3-to-mysql { }; + sqls = callPackage ../applications/misc/sqls { }; stdman = callPackage ../data/documentation/stdman { };