1 /*********************************************************************************************************************************** 2 Harness for Loading Test Configurations 3 ***********************************************************************************************************************************/ 4 #ifndef TEST_COMMON_HARNESS_CONFIG_H 5 #define TEST_COMMON_HARNESS_CONFIG_H 6 7 #include "config/config.h" 8 9 /*********************************************************************************************************************************** 10 Prefix for environment variables 11 ***********************************************************************************************************************************/ 12 #define HRN_PGBACKREST_ENV "PGBACKREST_" 13 14 /*********************************************************************************************************************************** 15 Config option constants 16 ***********************************************************************************************************************************/ 17 #define TEST_CIPHER_PASS "xmainx" 18 #define TEST_CIPHER_PASS_ARCHIVE "xarchivex" 19 20 /*********************************************************************************************************************************** 21 Load a test configuration 22 23 Automatically adds the exe, command (and role), lock-path, and log-path so executing the binary works locally or in a container. 24 There is no need to open log files, acquire locks, reset log levels, etc. 25 26 HRN_CFG_LOAD() is the preferred macro but if a configuration error is being tested with TEST_ERROR() then use hrnCfgLoadP() instead 27 since it will not log to the console and clutter the error log message. 28 ***********************************************************************************************************************************/ 29 typedef struct HrnCfgLoadParam 30 { 31 VAR_PARAM_HEADER; 32 ConfigCommandRole role; // Command role (defaults to main) 33 bool exeBogus; // Use pgbackrest-bogus as exe parameter 34 bool noStd; // Do not add standard options, e.g. lock-path 35 bool log; // Log parameters? (used internally by HRN_CFG_LOAD()) 36 const char *comment; // Comment 37 } HrnCfgLoadParam; 38 39 #define hrnCfgLoadP(commandId, argList, ...) \ 40 hrnCfgLoad(commandId, argList, (HrnCfgLoadParam){VAR_PARAM_INIT, __VA_ARGS__}) 41 42 #define HRN_CFG_LOAD(commandId, argList, ...) \ 43 do \ 44 { \ 45 hrnTestLogPrefix(__LINE__); \ 46 hrnCfgLoad(commandId, argList, (HrnCfgLoadParam){.log = true, __VA_ARGS__}); \ 47 } \ 48 while (0) 49 50 void hrnCfgLoad(ConfigCommand commandId, const StringList *argList, const HrnCfgLoadParam param); 51 52 /*********************************************************************************************************************************** 53 Configuration helper functions 54 55 These functions set options in the argument list using the option IDs rather than string constants. Each function has a "Key" 56 variant that works with indexed options and allows the key to be specified, e.g. hrnCfgArgKeyRawZ(cfgOptPgpath, 3, "/pg") will add 57 --pg3-path=/pg to the argument list. 58 ***********************************************************************************************************************************/ 59 void hrnCfgArgRaw(StringList *argList, ConfigOption optionId, const String *value); 60 void hrnCfgArgKeyRaw(StringList *argList, ConfigOption optionId, unsigned optionKey, const String *value); 61 62 void hrnCfgArgRawFmt(StringList *argList, ConfigOption optionId, const char *format, ...) 63 __attribute__((format(printf, 3, 4))); 64 void hrnCfgArgKeyRawFmt(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *format, ...) 65 __attribute__((format(printf, 4, 5))); 66 67 void hrnCfgArgRawZ(StringList *argList, ConfigOption optionId, const char *value); 68 void hrnCfgArgKeyRawZ(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *value); 69 70 void hrnCfgArgRawStrId(StringList *argList, ConfigOption optionId, StringId value); 71 void hrnCfgArgKeyRawStrId(StringList *argList, ConfigOption optionId, unsigned optionKey, StringId); 72 73 void hrnCfgArgRawBool(StringList *argList, ConfigOption optionId, bool value); 74 void hrnCfgArgKeyRawBool(StringList *argList, ConfigOption optionId, unsigned optionKey, bool value); 75 76 void hrnCfgArgRawNegate(StringList *argList, ConfigOption optionId); 77 void hrnCfgArgKeyRawNegate(StringList *argList, ConfigOption optionId, unsigned optionKey); 78 79 void hrnCfgArgRawReset(StringList *argList, ConfigOption optionId); 80 void hrnCfgArgKeyRawReset(StringList *argList, ConfigOption optionId, unsigned optionKey); 81 82 /*********************************************************************************************************************************** 83 Environment helper functions 84 85 Add and remove environment options, which are required to pass secrets, e.g. repo1-cipher-pass. 86 ***********************************************************************************************************************************/ 87 void hrnCfgEnvRaw(ConfigOption optionId, const String *value); 88 void hrnCfgEnvKeyRaw(ConfigOption optionId, unsigned optionKey, const String *value); 89 90 void hrnCfgEnvRawZ(ConfigOption optionId, const char *value); 91 void hrnCfgEnvKeyRawZ(ConfigOption optionId, unsigned optionKey, const char *value); 92 93 void hrnCfgEnvRemoveRaw(ConfigOption optionId); 94 void hrnCfgEnvKeyRemoveRaw(ConfigOption optionId, unsigned optionKey); 95 96 #endif 97