@@ -10,7 +10,15 @@ import ./make-test.nix ({ pkgs, ...} : {
1010
1111 {
1212 services.mysql.enable = true;
13− services.mysql.initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
13+ services.mysql.initialDatabases = [
14+ { name = "testdb"; schema = ./testdb.sql; }
15+ { name = "empty_testdb"; }
16+ ];
17+ # note that using pkgs.writeText here is generally not a good idea,
18+ # as it will store the password in world-readable /nix/store ;)
19+ services.mysql.initialScript = pkgs.writeText "mysql-init.sql" ''
20+ CREATE USER 'passworduser'@'localhost' IDENTIFIED BY 'password123';
21+ '';
1422 services.mysql.package = pkgs.mysql;
1523 };
1624
@@ -36,11 +44,14 @@ import ./make-test.nix ({ pkgs, ...} : {
3644 startAll;
3745
3846 $mysql->waitForUnit("mysql");
39− $mysql->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4");
47+ $mysql->succeed("echo 'use empty_testdb;' | mysql -u root");
48+ $mysql->succeed("echo 'use testdb; select * from tests;' | mysql -u root -N | grep 4");
49+ # ';' acts as no-op, just check whether login succeeds with the user created from the initialScript
50+ $mysql->succeed("echo ';' | mysql -u passworduser --password=password123");
4051
4152 $mariadb->waitForUnit("mysql");
4253 $mariadb->succeed("echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser");
4354 $mariadb->succeed("echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser");
44− $mariadb->succeed("echo 'use testdb; select test_id from tests' | sudo -u testuser mysql -u testuser -N | grep 42");
55+ $mariadb->succeed("echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42");
4556 '';
4657})