From 6cb30340d3b39a4b85e2f0df9da284a7541c83cf Mon Sep 17 00:00:00 2001 From: silverqx Date: Wed, 24 Jul 2024 20:50:16 +0200 Subject: [PATCH] tests tried to avoid edge cases fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto tests don't fail if the tom example migrations are migrated, they will be rolled back and the migrations_example migration repository table will be uninstalled. This is a very rare edge case, but it can still happen during local development, auto test are more robust now. 🕺 --- .../functional/tom/migrate/tst_migrate.cpp | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/auto/functional/tom/migrate/tst_migrate.cpp b/tests/auto/functional/tom/migrate/tst_migrate.cpp index 218d47103..15715d3c0 100644 --- a/tests/auto/functional/tom/migrate/tst_migrate.cpp +++ b/tests/auto/functional/tom/migrate/tst_migrate.cpp @@ -77,9 +77,11 @@ private Q_SLOTS: /*! Prepare arguments and invoke runCommand(). */ [[nodiscard]] static int invokeCommand(const QString &connection, const QString &name, - const std::vector &arguments = {}); + const std::vector &arguments = {}, + const QString &migrationTable = MigrationsTable); /*! Create a tom application instance and invoke the given command. */ - static int runCommand(int &argc, const std::vector &argv); + static int runCommand(int &argc, const std::vector &argv, + const QString &migrationTable); /*! Invoke the status command to obtain results. */ inline static int invokeTestStatusCommand(const QString &connection); @@ -96,8 +98,10 @@ private Q_SLOTS: /*! Throw if the environment is production because it needs confirmation. */ static void throwIfWrongEnvironment(const char *environmentEnvName); - /*! Migrations table name. */ + /*! Migrations table name (used by this test case). */ inline static const auto MigrationsTable = sl("migrations_unit_testing"); + /*! Migrations table name (to cleanup the tom example migrations only). */ + inline static const auto MigrationsTomTable = sl("migrations_example"); /*! Created database connections (needed by the cleanupTestCase()). */ QStringList m_connections; @@ -766,7 +770,8 @@ void tst_Migrate::refresh_Step_StepMigrate() const /* private */ int tst_Migrate::invokeCommand(const QString &connection, const QString &name, - const std::vector &arguments) + const std::vector &arguments, + const QString &migrationTable) { static const auto connectionTmpl = sl("--database=%1"); @@ -791,10 +796,11 @@ int tst_Migrate::invokeCommand(const QString &connection, const QString &name, int argc = static_cast(argv.size()); - return runCommand(argc, argv); + return runCommand(argc, argv, migrationTable); } -int tst_Migrate::runCommand(int &argc, const std::vector &argv) +int tst_Migrate::runCommand(int &argc, const std::vector &argv, + const QString &migrationTable) { // Current environment variable name const auto *const environmentEnvName = "TOM_TESTS_ENV"; @@ -806,7 +812,7 @@ int tst_Migrate::runCommand(int &argc, const std::vector &argv) // env. should be always local or development return TomApplication(argc, const_cast(argv.data()), Databases::managerShared(), environmentEnvName, - MigrationsTable) + migrationTable) .migrations