Исходный код СУБД 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
/***********************************************************************************************************************************
Test Exec Configuration
***********************************************************************************************************************************/
#include "common/crypto/common.h"
 
#include "harness/config.h"
 
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
static void
testRun(void)
{
    FUNCTION_HARNESS_VOID();
 
    // *****************************************************************************************************************************
    if (testBegin("cfgExecParam()"))
    {
        StringList *argList = strLstNew();
        hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
        hrnCfgArgRawZ(argList, cfgOptArchiveTimeout, "5");
        hrnCfgArgRawZ(argList, cfgOptBufferSize, "64KiB");
        hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
        hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, TEST_PATH "/db path");
        hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 2, "/db2");
        hrnCfgArgRawBool(argList, cfgOptLogSubprocess, true);
        hrnCfgArgRawBool(argList, cfgOptConfig, false);
        hrnCfgArgRawReset(argList, cfgOptNeutralUmask);
        hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
        hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
 
        // Set repo1-cipher-pass to make sure it is not passed on the command line
        hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
        HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .noStd = true);
        hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
 
        TEST_RESULT_STRLST_Z(
            cfgExecParam(cfgCmdArchiveGet, cfgCmdRoleAsync, NULL, false, true),
            "--archive-async\n--buffer-size=64KiB\n--no-config\n--exec-id=1-test\n--log-subprocess\n--reset-neutral-umask\n"
            "--pg1-path=\"" TEST_PATH "/db path\"\n--pg2-path=/db2\n--repo1-path=" TEST_PATH "/repo\n--stanza=test1\n"
            "archive-get:async\n",
            "exec archive-get -> archive-get:async");
 
        // Replace an option that is valid for the specified command but not for the command being run. The replacement is at an
        // index above the first to be sure every index of the group is searched.
        KeyValue *const optionReplacePg = kvNew();
        kvPut(optionReplacePg, VARSTRDEF("pg2-socket-path"), VARSTRDEF("/socket2"));
 
        TEST_RESULT_STRLST_Z(
            cfgExecParam(cfgCmdBackup, cfgCmdRoleMain, optionReplacePg, false, false),
            "--archive-timeout=5\n--buffer-size=64KiB\n--no-config\n--exec-id=1-test\n--log-subprocess\n--reset-neutral-umask\n"
            "--pg1-path=" TEST_PATH "/db path\n--pg2-path=/db2\n--pg2-socket-path=/socket2\n--repo1-path=" TEST_PATH "/repo\n"
            "--stanza=test1\nbackup\n",
            "exec archive-get -> backup");
 
        // -------------------------------------------------------------------------------------------------------------------------
        argList = strLstNew();
        hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
        hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
        hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH "/db path");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "1");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "2");
        hrnCfgArgRawZ(argList, cfgOptRecoveryOption, "a=b");
        hrnCfgArgRawZ(argList, cfgOptRecoveryOption, "c=d");
        hrnCfgArgRawReset(argList, cfgOptLogPath);
 
        hrnCfgEnvRawZ(cfgOptRepoHost, "bogus");
        HRN_CFG_LOAD(cfgCmdRestore, argList, .noStd = true);
        hrnCfgEnvRemoveRaw(cfgOptRepoHost);
 
        KeyValue *optionReplace = kvNew();
        kvPut(optionReplace, VARSTRDEF("repo1-path"), VARSTRDEF("/replace/path"));
        kvPut(optionReplace, VARSTRDEF("stanza"), NULL);
        kvPut(optionReplace, VARSTRDEF(CFGOPT_LOG_PATH), VARSTRDEF("/log"));
 
        TEST_RESULT_STRLST_Z(
            cfgExecParam(cfgCmdRestore, cfgCmdRoleMain, optionReplace, true, false),
            "--db-include=1\n--db-include=2\n--exec-id=1-test\n--log-path=/log\n--pg1-path=" TEST_PATH "/db path\n"
            "--recovery-option=a=b\n--recovery-option=c=d\n--repo1-path=/replace/path\nrestore\n",
            "exec restore -> restore");
    }
 
    FUNCTION_HARNESS_RETURN_VOID();
}