Исходный код СУБД 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
/***********************************************************************************************************************************
Test Common Command Routines
***********************************************************************************************************************************/
#include <fcntl.h>
#include <unistd.h>
 
#include "common/stat.h"
#include "version.h"
 
#include "harness/config.h"
 
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
static void
testRun(void)
{
    FUNCTION_HARNESS_VOID();
 
    // *****************************************************************************************************************************
    if (testBegin("cmdBegin() and cmdEnd()"))
    {
        cmdInit();
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("single parameter");
 
        StringList *argList = strLstNew();
        hrnCfgArgRawZ(argList, cfgOptStanza, "test");
        hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
        hrnCfgArgRawZ(argList, cfgOptArchiveTimeout, "10");
        hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg1");
        strLstAddZ(argList, "param1");
        HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .noStd = true);
 
        TEST_RESULT_VOID(cmdBegin(), "command begin with command parameter");
        TEST_RESULT_LOG(
            "P00   INFO: archive-get command begin " PROJECT_VERSION ": [param1] --archive-async --archive-timeout=10"
            " --exec-id=1-test --pg1-path=/pg1 --stanza=test");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("multiple parameters");
 
        argList = strLstNew();
        hrnCfgArgRawZ(argList, cfgOptStanza, "test");
        hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
        hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg1");
        strLstAddZ(argList, "param1");
        strLstAddZ(argList, "param 2");
        HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .noStd = true);
 
        TEST_RESULT_VOID(cmdBegin(), "command begin with command parameters");
        TEST_RESULT_LOG(
            "P00   INFO: archive-get command begin " PROJECT_VERSION ": [param1, \"param 2\"] --archive-async --exec-id=1-test"
            " --pg1-path=/pg1 --stanza=test");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("reset, negate, list, hash options");
 
        argList = strLstNew();
        hrnCfgArgRawNegate(argList, cfgOptConfig);
        hrnCfgArgRawZ(argList, cfgOptStanza, "test");
        hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
        hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 2, "/pg2");
        hrnCfgArgRawZ(argList, cfgOptRepoCipherType, "aes-256-cbc");
        hrnCfgArgRawReset(argList, cfgOptRepoHost);
        hrnCfgArgRawZ(argList, cfgOptRepoPath, "/path/to the/repo");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "db1");
        hrnCfgArgRawZ(argList, cfgOptDbInclude, "db2");
        hrnCfgArgRawZ(argList, cfgOptRecoveryOption, "standby_mode=on");
        hrnCfgArgRawZ(argList, cfgOptRecoveryOption, "primary_conninfo=blah");
        hrnCfgEnvRawZ(cfgOptRepoCipherPass, "SECRET-STUFF");
        HRN_CFG_LOAD(cfgCmdRestore, argList, .noStd = true);
 
        TEST_RESULT_VOID(cmdBegin(), "command begin");
 
        TEST_RESULT_LOG(
            "P00   INFO: restore command begin " PROJECT_VERSION ": --no-config --db-include=db1 --db-include=db2 --exec-id=1-test"
            " --pg1-path=/pg1 --pg2-path=/pg2 --recovery-option=standby_mode=on --recovery-option=primary_conninfo=blah"
            " --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --reset-repo1-host --repo1-path=\"/path/to the/repo\""
            " --stanza=test");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("check options in cache");
 
        TEST_RESULT_STR_Z(
            cmdOption(), " --no-config --db-include=db1 --db-include=db2 --exec-id=1-test --pg1-path=/pg1 --pg2-path=/pg2"
            " --recovery-option=standby_mode=on --recovery-option=primary_conninfo=blah --repo1-cipher-pass=<redacted>"
            " --repo1-cipher-type=aes-256-cbc --reset-repo1-host --repo1-path=\"/path/to the/repo\" --stanza=test", "option cache");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("command begin does not log when level is too low");
 
        harnessLogLevelSet(logLevelWarn);
        TEST_RESULT_VOID(cmdBegin(), "command begin");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("command end does not log when level is too low");
 
        TEST_RESULT_VOID(cmdEnd(NULL), "command end");
        harnessLogLevelReset();
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("command end with error");
 
        TEST_RESULT_VOID(cmdEnd(STRDEF("aborted with exception [025]")), "command end");
        TEST_RESULT_LOG("P00   INFO: restore command end: aborted with exception [025]");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("command end with time");
 
        TEST_RESULT_VOID(cmdEnd(NULL), "command end");
        hrnLogReplaceAdd("\\([0-9]+ms\\)", "[0-9]+", "TIME", false);
        TEST_RESULT_LOG(
            "P00   INFO: restore command end: completed successfully ([TIME]ms)");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("command end with stat and without time");
 
        statInc(STRDEF("test"));
        cfgOptionSet(cfgOptLogTimestamp, cfgSourceParam, BOOL_FALSE_VAR);
 
        harnessLogLevelSet(logLevelDetail);
 
        TEST_RESULT_VOID(cmdEnd(NULL), "command end");
        TEST_RESULT_LOG(
            "P00 DETAIL: statistics: {\"test\":{\"total\":1}}\n"
            "P00   INFO: restore command end: completed successfully");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("switch to a new command so some options are not valid");
 
        cfgCommandSet(cfgCmdArchiveGet, cfgCmdRoleMain);
 
        TEST_RESULT_VOID(cmdBegin(), "command begin");
        TEST_RESULT_LOG(
            "P00   INFO: archive-get command begin " PROJECT_VERSION ": --no-config --exec-id=1-test --log-timestamp"
            " --pg1-path=/pg1 --pg2-path=/pg2 --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --reset-repo1-host"
            " --repo1-path=\"/path/to the/repo\" --stanza=test");
 
        harnessLogLevelReset();
    }
 
    FUNCTION_HARNESS_RETURN_VOID();
}