]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Add unit tests for client program execution
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Thu, 20 Jan 2022 09:34:00 +0000 (10:34 +0100)
committerKarl Fleischmann <karl.fleischmann@open-xchange.com>
Tue, 1 Feb 2022 06:43:03 +0000 (07:43 +0100)
- Add unit test that covers program_client_wait(), in which the script
  execution environment needs to wait for a still running asynchronous
  client program, and
- add unit test that covers a synchronous program_client_run().

src/lib-program-client/test-program-client-unix.c

index e524c887e3c7e4b4deb5285015fc57aa9542b9f8..4f56617d8b439bfe8ee316190710e720ecc0c7e1 100644 (file)
@@ -37,6 +37,7 @@ static struct test_server {
        struct io *io;
        struct timeout *to;
        struct test_client *client;
+       struct program_client *async_client;
        int listen_fd;
 } test_globals;
 
@@ -258,6 +259,11 @@ static void test_program_teardown(void)
        if (test_globals.client != NULL)
                test_program_client_destroy(&test_globals.client);
 
+       if (test_globals.async_client != NULL) {
+               program_client_wait(test_globals.async_client);
+               program_client_destroy(&test_globals.async_client);
+       }
+
        io_remove(&test_globals.io);
        i_close_fd(&test_globals.listen_fd);
        io_loop_destroy(&test_globals.ioloop);
@@ -408,6 +414,52 @@ static void test_program_noreply(void)
        test_end();
 }
 
+static void test_program_sync(void)
+{
+       struct program_client *pc;
+       int ret;
+
+       const char *const args[] = {
+               "test_program_io", NULL, NULL
+       };
+
+       test_begin("test_program_sync");
+
+       pc = program_client_unix_create(TEST_SOCKET, args, &pc_set, TRUE);
+       ret = program_client_run(pc);
+       test_assert(ret == 1);
+
+       program_client_destroy(&pc);
+       test_program_end(test_globals.client);
+
+       test_end();
+}
+
+static void test_program_async_wait_finish(enum program_client_exit_status ret,
+                                          struct program_client *client ATTR_UNUSED)
+{
+       test_assert(ret == PROGRAM_CLIENT_EXIT_STATUS_SUCCESS);
+       io_loop_stop(current_ioloop);
+}
+
+static void test_program_async_wait(void)
+{
+       const char *const args[] = {
+               "test_program_io", NULL, NULL
+       };
+
+       test_begin("test_program_async_wait");
+
+       test_globals.async_client = program_client_unix_create(TEST_SOCKET,
+                       args, &pc_set, TRUE);
+
+       program_client_run_async(test_globals.async_client,
+                                test_program_async_wait_finish,
+                                test_globals.async_client);
+
+       test_end();
+}
+
 int main(int argc, char *argv[])
 {
        int ret, c;
@@ -418,6 +470,8 @@ int main(int argc, char *argv[])
                test_program_io,
                test_program_failure,
                test_program_noreply,
+               test_program_sync,
+               test_program_async_wait,
                test_program_teardown,
                NULL
        };