Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/***********************************************************************************************************************************
Test Help Command
***********************************************************************************************************************************/
#include "config/load.h"
#include "config/parse.h"
#include "storage/helper.h"
#include "storage/posix/storage.h"
#include "version.h"
 
#include "harness/config.h"
#include "harness/storage.h"
 
/***********************************************************************************************************************************
Configuration load with just enough functionality to test help
***********************************************************************************************************************************/
static void
testCfgLoad(const StringList *const argList)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING_LIST, argList);
    FUNCTION_HARNESS_END();
 
    // Parse config
    cfgParseP(storageLocal(), strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true);
 
    // Apply special option rules
    cfgLoadUpdateOption();
 
    FUNCTION_HARNESS_RETURN_VOID();
}
 
/***********************************************************************************************************************************
Last blocks of help text, where a block is the text between blank lines
***********************************************************************************************************************************/
static String *
testHelpBlockLast(const String *const help, const unsigned int blockTotal)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING, help);
        FUNCTION_HARNESS_PARAM(UINT, blockTotal);
    FUNCTION_HARNESS_END();
 
    const StringList *const blockList = strLstNewSplitZ(help, "\n\n");
    StringList *const result = strLstNew();
 
    ASSERT(blockTotal > 0 && blockTotal <= strLstSize(blockList));
 
    for (unsigned int blockIdx = strLstSize(blockList) - blockTotal; blockIdx < strLstSize(blockList); blockIdx++)
        strLstAdd(result, strLstGet(blockList, blockIdx));
 
    FUNCTION_HARNESS_RETURN(STRING, strLstJoin(result, "\n\n"));
}
 
/***********************************************************************************************************************************
First blocks of help text, where a block is the text between blank lines
***********************************************************************************************************************************/
static String *
testHelpBlockFirst(const String *const help, const unsigned int blockTotal)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING, help);
        FUNCTION_HARNESS_PARAM(UINT, blockTotal);
    FUNCTION_HARNESS_END();
 
    const StringList *const blockList = strLstNewSplitZ(help, "\n\n");
    StringList *const result = strLstNew();
 
    ASSERT(blockTotal > 0 && blockTotal <= strLstSize(blockList));
 
    for (unsigned int blockIdx = 0; blockIdx < blockTotal; blockIdx++)
        strLstAdd(result, strLstGet(blockList, blockIdx));
 
    FUNCTION_HARNESS_RETURN(STRING, strLstJoin(result, "\n\n"));
}
 
/***********************************************************************************************************************************
Block of help text that begins with a prefix. NULL when no block begins with the prefix.
***********************************************************************************************************************************/
static String *
testHelpBlockFind(const String *const help, const char *const prefix)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING, help);
        FUNCTION_HARNESS_PARAM(STRINGZ, prefix);
    FUNCTION_HARNESS_END();
 
    const StringList *const blockList = strLstNewSplitZ(help, "\n\n");
    String *result = NULL;
 
    for (unsigned int blockIdx = 0; blockIdx < strLstSize(blockList); blockIdx++)
    {
        if (strBeginsWithZ(strLstGet(blockList, blockIdx), prefix))
        {
            result = strDup(strLstGet(blockList, blockIdx));
            break;
        }
    }
 
    FUNCTION_HARNESS_RETURN(STRING, result);
}
 
/***********************************************************************************************************************************
Section headings of command help
***********************************************************************************************************************************/
static String *
testHelpSectionList(const String *const help)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING, help);
    FUNCTION_HARNESS_END();
 
    const StringList *const lineList = strLstNewSplitZ(help, "\n");
    String *const result = strNew();
 
    for (unsigned int lineIdx = 0; lineIdx < strLstSize(lineList); lineIdx++)
    {
        if (strEndsWithZ(strLstGet(lineList, lineIdx), " Options:"))
            strCatFmt(result, "%s\n", strZ(strLstGet(lineList, lineIdx)));
    }
 
    FUNCTION_HARNESS_RETURN(STRING, result);
}
 
/***********************************************************************************************************************************
Entry for an option in command help, i.e. the line with the option name and the lines its summary wraps onto. NULL when the option
is not listed.
***********************************************************************************************************************************/
static String *
testHelpOption(const String *const help, const char *const optionName)
{
    FUNCTION_HARNESS_BEGIN();
        FUNCTION_HARNESS_PARAM(STRING, help);
        FUNCTION_HARNESS_PARAM(STRINGZ, optionName);
    FUNCTION_HARNESS_END();
 
    const StringList *const lineList = strLstNewSplitZ(help, "\n");
    const String *const optionPrefix = strNewFmt("  --%s ", optionName);
    String *result = NULL;
 
    for (unsigned int lineIdx = 0; lineIdx < strLstSize(lineList); lineIdx++)
    {
        const String *const line = strLstGet(lineList, lineIdx);
 
        // Line with the option name
        if (result == NULL)
        {
            if (strBeginsWith(line, optionPrefix))
                result = strCatFmt(strNew(), "%s\n", strZ(line));
        }
        // Line the summary wraps onto
        else if (strBeginsWithZ(line, "    "))
            strCatFmt(result, "%s\n", strZ(line));
        else
            break;
    }
 
    FUNCTION_HARNESS_RETURN(STRING, result);
}
 
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
static void
testRun(void)
{
    FUNCTION_HARNESS_VOID();
 
    // Program name a version are used multiple times
    const char *helpVersion = PROJECT_NAME " " PROJECT_VERSION;
 
    // General help text is used in more than one test
    const char *generalHelp = zNewFmt(
        "%s - General help\n"
        "\n"
        "Usage:\n"
        "    pgbackrest [options] [command]\n"
        "\n"
        "Commands:\n"
        "    annotate        add or modify backup annotation\n"
        "    archive-get     get a WAL segment from the archive\n"
        "    archive-push    push a WAL segment to the archive\n"
        "    backup          backup a database cluster\n"
        "    check           check the configuration\n"
        "    expire          expire backups that exceed retention\n"
        "    help            get help\n"
        "    info            retrieve information about backups\n"
        "    repo-get        get a file from a repository\n"
        "    repo-ls         list files in a repository\n"
        "    restore         restore a database cluster\n"
        "    server          pgBackRest server\n"
        "    server-ping     ping pgBackRest server\n"
        "    stanza-create   create the required stanza data\n"
        "    stanza-delete   delete a stanza\n"
        "    stanza-upgrade  upgrade a stanza\n"
        "    start           allow pgBackRest processes to run\n"
        "    stop            stop pgBackRest processes from running\n"
        "    verify          verify contents of a repository\n"
        "    version         get version\n"
        "\n"
        "Use 'pgbackrest help [command]' for more information.\n",
        helpVersion);
 
    // *****************************************************************************************************************************
    if (testBegin("helpRenderSplitSize()"))
    {
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF("abc def"), " ", 3), "abc\ndef\n", "two items");
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF("abc def"), " ", 4), "abc\ndef\n", "two items, size > each item");
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF("abc def ghi"), " ", 4), "abc\ndef\nghi\n", "three items");
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF("abc def ghi"), " ", 8), "abc def\nghi\n", "three items, size > first two");
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF("abc def "), " ", 4), "abc\ndef \n", "two items, size includes space");
        TEST_RESULT_STRLST_Z(helpRenderSplitSize(STRDEF(""), " ", 1), "\n", "empty list");
 
        TEST_RESULT_STRLST_Z(
            helpRenderSplitSize(STRDEF("this is a short sentence"), " ", 10),
            "this is a\n"
            "short\n"
            "sentence\n",
            "variable word sizes");
    }
 
    // *****************************************************************************************************************************
    if (testBegin("helpRenderText() and helpRenderSummary()"))
    {
        TEST_RESULT_STR_Z(
            helpRenderText(STRDEF("this is a short sentence"), false, false, 0, false, 80), "this is a short sentence", "one line");
 
        TEST_RESULT_STR_Z(
            helpRenderText(STRDEF("this is a short sentence"), false, false, 4, false, 14),
            "this is a\n"
            "    short\n"
            "    sentence",
            "three lines, no indent first");
 
        TEST_RESULT_STR_Z(
            helpRenderText(STRDEF("this is a short sentence"), true, true, 4, true, 132),
            "    this is a short sentence\n"
            "\n"
            "    FOR BETA TESTING ONLY. DO NOT USE IN PRODUCTION.",
            "beta feature");
 
        TEST_RESULT_STR_Z(
            helpRenderText(STRDEF("This is a short paragraph.\n\nHere is another one."), true, false, 2, true, 16),
            "  This is a\n"
            "  short\n"
            "  paragraph.\n"
            "\n"
            "  Here is\n"
            "  another one.\n"
            "\n"
            "  FOR INTERNAL\n"
            "  USE ONLY. DO\n"
            "  NOT USE IN\n"
            "  PRODUCTION.",
            "two paragraphs, indent first, internal");
 
        TEST_RESULT_STR_Z(helpRenderSummary(STRDEF("Summary.")), "summary", "render summary");
    }
 
    // *****************************************************************************************************************************
    if (testBegin("helpRender()"))
    {
        StringList *argList = NULL;
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("version");
 
        const char *versionOnly = zNewFmt("%s\n", helpVersion);
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "version");
        TEST_RESULT_VOID(testCfgLoad(argList), "version from version command");
        TEST_RESULT_STR_Z(helpRender(), versionOnly, "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "version");
        hrnCfgArgRawZ(argList, cfgOptOutput, "text");
        TEST_RESULT_VOID(testCfgLoad(argList), "version text output from version command");
        TEST_RESULT_STR_Z(helpRender(), versionOnly, "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "version");
        hrnCfgArgRawZ(argList, cfgOptOutput, "num");
        TEST_RESULT_VOID(testCfgLoad(argList), "version num output from version command");
        TEST_RESULT_STR_Z(helpRender(), zNewFmt("%d", PROJECT_VERSION_NUM), "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "--version");
        TEST_RESULT_VOID(testCfgLoad(argList), "version from version option");
        TEST_RESULT_STR_Z(helpRender(), versionOnly, "check text");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("general invocation");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        TEST_RESULT_VOID(testCfgLoad(argList), "help from empty command line");
        TEST_RESULT_STR_Z(helpRender(), generalHelp, "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        TEST_RESULT_VOID(testCfgLoad(argList), "help from help command");
        TEST_RESULT_STR_Z(helpRender(), generalHelp, "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "--version");
        strLstAddZ(argList, "--help");
        TEST_RESULT_VOID(testCfgLoad(argList), "help from help option");
        TEST_RESULT_STR_Z(helpRender(), generalHelp, "check text");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("restore command");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "restore");
        hrnCfgArgRawZ(argList, cfgOptBufferSize, "32768");
        hrnCfgArgRawZ(argList, cfgOptRepoCipherType, "aes-256-cbc");
        hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
        hrnCfgArgKeyRawZ(argList, cfgOptRepoHost, 1, "backup.example.net");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoHost, 2, "dr.test.org");
        hrnCfgArgRawZ(argList, cfgOptLinkMap, "/link1=/dest1");
        hrnCfgArgRawZ(argList, cfgOptLinkMap, "/link2=/dest2");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "db1");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "db2");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for restore command");
        hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
 
        const String *commandHelp = NULL;
        TEST_ASSIGN(commandHelp, helpRender(), "render help");
 
        TEST_RESULT_STR_Z(
            testHelpBlockFirst(commandHelp, 2), zNewFmt("%s - 'restore' command help\n\nRestore a database cluster.", helpVersion),
            "header and summary");
        TEST_RESULT_STR_Z(
            testHelpBlockLast(commandHelp, 1), "Use 'pgbackrest help restore [option]' for more information.\n", "footer");
        TEST_RESULT_STR_Z(
            testHelpSectionList(commandHelp),
            "Command Options:\n"
            "General Options:\n"
            "Log Options:\n"
            "Maintainer Options:\n"
            "Repository Options:\n"
            "Stanza Options:\n",
            "sections");
 
        // The column width is set by the longest option name
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "repo-sftp-private-key-passphrase"),
            "  --repo-sftp-private-key-passphrase  SFTP private key passphrase\n",
            "longest option name");
 
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "force"),
            "  --force                             force a restore [default=n]\n",
            "default on the same line");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "archive-mode"),
            "  --archive-mode                      preserve or disable archiving on restored\n"
            "                                      cluster [default=preserve]\n",
            "summary wraps with default");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "repo-host-config"),
            "  --repo-host-config                  pgBackRest repository host configuration\n"
            "                                      file\n"
            "                                      [default=/etc/pgbackrest/pgbackrest.conf]\n",
            "summary and default wrap");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "buffer-size"),
            "  --buffer-size                       buffer size for I/O operations\n"
            "                                      [current=32768, default=1MiB]\n",
            "current and default");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "cmd"),
            "  --cmd                               pgBackRest command\n"
            "                                      [default=/path/to/pgbackrest]\n",
            "dynamic default");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "db-include"),
            "  --db-include                        restore only specified databases\n"
            "                                      [current=db1, db2]\n",
            "list current");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "link-map"),
            "  --link-map                          modify the destination of a symlink\n"
            "                                      [current=/link1=/dest1, /link2=/dest2]\n",
            "hash current");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "repo-cipher-pass"),
            "  --repo-cipher-pass                  repository cipher passphrase\n"
            "                                      [current=<redacted>]\n",
            "secure current");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "repo-cipher-type"),
            "  --repo-cipher-type                  cipher used to encrypt the repository\n"
            "                                      [current=<multi>, default=none]\n",
            "multiple current with default");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "repo-host"),
            "  --repo-host                         repository host when operating remotely\n"
            "                                      [current=<multi>]\n",
            "multiple current");
        TEST_RESULT_STR_Z(
            testHelpOption(commandHelp, "pg-version-force"),
            "  --pg-version-force                  force PostgreSQL version\n",
            "maintainer option");
        TEST_RESULT_STR(testHelpOption(commandHelp, "job-retry"), NULL, "internal option not listed");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("errors with specified options");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "archive-push");
        strLstAddZ(argList, "buffer-size");
        strLstAddZ(argList, "buffer-size");
        TEST_RESULT_VOID(testCfgLoad(argList), "parse too many options");
        TEST_ERROR(helpRender(), ParamInvalidError, "only one option allowed for option help");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "archive-push");
        strLstAddZ(argList, BOGUS_STR);
        TEST_RESULT_VOID(testCfgLoad(argList), "parse bogus option");
        TEST_ERROR(helpRender(), OptionInvalidError, "option 'BOGUS' is not valid for command 'archive-push'");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, CFGCMD_HELP);
        strLstAddZ(argList, CFGCMD_ARCHIVE_PUSH);
        strLstAddZ(argList, CFGOPT_PROCESS);
        TEST_RESULT_VOID(testCfgLoad(argList), "parse option invalid for command");
        TEST_ERROR(helpRender(), OptionInvalidError, "option 'process' is not valid for command 'archive-push'");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("default and current option value");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "archive-push");
        strLstAddZ(argList, "buffer-size");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for archive-push command, buffer-size option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 1), "default: 1MiB\n", "check text");
 
        // Set a current value
        hrnCfgArgRawZ(argList, cfgOptBufferSize, "32k");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for archive-push command, buffer-size option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 1), "current: 32k\ndefault: 1MiB\n", "check text, current value");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("deprecated host option names");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "archive-push");
        strLstAddZ(argList, "repo1-s3-host");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for archive-push command, repo1-s3-host option");
        TEST_RESULT_STR_Z(
            testHelpBlockLast(helpRender(), 1), "deprecated names: repo-azure-host, repo-s3-host\n", "check text");
 
        // Set a current value for deprecated option name
        hrnCfgArgRawZ(argList, cfgOptRepoType, "s3");
        strLstAddZ(argList, "--repo1-s3-host=s3-host");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for archive-push command, repo1-s3-host option");
        TEST_RESULT_STR_Z(
            testHelpBlockLast(helpRender(), 2), "current: s3-host\n\ndeprecated names: repo-azure-host, repo-s3-host\n",
            "check text, current value");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("cipher pass redacted");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        hrnCfgArgRawZ(argList, cfgOptRepoCipherType, "aes-256-cbc");
        hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
        strLstAddZ(argList, "archive-push");
        strLstAddZ(argList, "repo-cipher-pass");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for archive-push command, repo1-s3-host option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 1), "current: <redacted>\n", "check text");
        hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("deprecated and new option name produce same results");
 
        #define TEST_HELP_HARDLINK                                                                                                 \
            "default: n\n"                                                                                                         \
            "\n"                                                                                                                   \
            "deprecated name: hardlink\n"
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "backup");
        strLstAddZ(argList, "repo-hardlink");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for backup command, repo-hardlink option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 2), TEST_HELP_HARDLINK, "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "backup");
        strLstAddZ(argList, "hardlink");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for backup command, deprecated hardlink option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 2), TEST_HELP_HARDLINK, "check text");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("minimum repository format");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "expire");
        strLstAddZ(argList, "repo-cipher-rotate");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for expire command, repo-cipher-rotate option");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 1), "minimum repository format: 6\n", "check text");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        hrnCfgArgRawZ(argList, cfgOptRepoCipherType, "aes-256-cbc");
        hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
        strLstAddZ(argList, "expire");
        strLstAddZ(argList, "repo-cipher-rotate");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for expire command, repo-cipher-rotate option with default");
        TEST_RESULT_STR_Z(testHelpBlockLast(helpRender(), 1), "default: 90d\nminimum repository format: 6\n", "check text");
        hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("check admonition");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "backup");
        strLstAddZ(argList, "repo-retention-archive");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for backup command, repo-retention-archive option");
 
        const String *optionHelp = NULL;
        TEST_ASSIGN(optionHelp, helpRender(), "render help");
 
        TEST_RESULT_STR_Z(
            testHelpBlockFirst(optionHelp, 2),
            zNewFmt(
                "%s - 'backup' command - 'repo-retention-archive' option help\n"
                "\n"
                "Number of backups worth of continuous WAL to retain.",
                helpVersion),
            "header and summary");
        TEST_RESULT_STR_Z(
            testHelpBlockFind(optionHelp, "NOTE: "),
            "NOTE: WAL segments required to make a backup consistent are always retained\n"
            "until the backup is expired regardless of how this option is configured.",
            "admonition");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("multiple current values (with one missing)");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoHost, 1, "backup.example.net");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoHost, 3, "dr.test.org");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "restore");
        strLstAddZ(argList, "repo-host");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for restore command, repo-host option");
        TEST_RESULT_STR_Z(
            testHelpBlockLast(helpRender(), 2),
            "current:\n"
            "  repo1: backup.example.net\n"
            "  repo3: dr.test.org\n"
            "\n"
            "deprecated name: backup-host\n",
            "check text");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("multiple current values (with one unset)");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoType, 1, "s3");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoHost, 3, "dr.test.org");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "restore");
        strLstAddZ(argList, "repo-host");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for restore command, repo-host option");
        TEST_RESULT_STR_Z(
            testHelpBlockLast(helpRender(), 2),
            "current:\n"
            "  repo3: dr.test.org\n"
            "\n"
            "deprecated name: backup-host\n",
            "check text");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("multiple default values");
 
        argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoType, 1, "s3");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoType, 2, "azure");
        hrnCfgArgKeyRawZ(argList, cfgOptRepoType, 3, "gcs");
        strLstAddZ(argList, "help");
        strLstAddZ(argList, "restore");
        strLstAddZ(argList, "repo-storage-upload-chunk-size");
        TEST_RESULT_VOID(testCfgLoad(argList), "help for restore command, repo-storage-upload-chunk-size option");
 
        // There is currently no way for some defaults to be NULL and others not but it could happen in the future
        cfgOptionIdxSet(cfgOptRepoStorageUploadChunkSize, 2, cfgSourceDefault, NULL);
 
        TEST_RESULT_STR_Z(
            testHelpBlockLast(helpRender(), 1),
            "default:\n"
            "  repo1: 5MiB\n"
            "  repo2: 4MiB\n",
            "check text");
    }
 
    // *****************************************************************************************************************************
    if (testBegin("cmdHelp() to file"))
    {
        StringList *argList = strLstNew();
        strLstAddZ(argList, "/path/to/pgbackrest");
        TEST_RESULT_VOID(testCfgLoad(argList), "parse help from empty command line");
 
        // Redirect stdout to a file
        int stdoutSave = dup(STDOUT_FILENO);
 
        THROW_ON_SYS_ERROR(freopen(TEST_PATH "/stdout.help", "w", stdout) == NULL, FileWriteError, "unable to reopen stdout");
 
        // Not in a test wrapper to avoid writing to stdout
        cmdHelp();
 
        // Restore normal stdout
        dup2(stdoutSave, STDOUT_FILENO);
 
        Storage *storage = storagePosixNewP(TEST_PATH_STR);
        TEST_STORAGE_GET(storage, TEST_PATH "/stdout.help", generalHelp, .comment = "check text sent to file");
    }
 
    FUNCTION_HARNESS_RETURN_VOID();
}