1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-20 04:59:25 +02:00
pgbackrest/libc/xs/config/configTest.xs
David Steele 2a4ff2f904 Split cfgLoad() into multiple functions to make testing easier.
Mainly this helps with unit tests that need to do log expect testing. Add harnessCfgLoad() test function, which allows a new config to be loaded for unit testing without resetting log functions, opening a log file, or taking locks.
2018-04-13 16:05:52 -04:00

39 lines
1.6 KiB
Plaintext

# ----------------------------------------------------------------------------------------------------------------------------------
# Config Test Perl Exports
# ----------------------------------------------------------------------------------------------------------------------------------
MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC
####################################################################################################################################
# Parse command line and return a JSON object with results
####################################################################################################################################
SV *
cfgParseTest(backrestBin, parseParam)
const char *backrestBin
const char *parseParam
CODE:
RETVAL = NULL;
ERROR_XS_BEGIN()
{
// This should run in a temp context but for some reason getopt_long gets upset when if gets called again after the previous
// arg list being freed. So, this is a memory leak but it is only used for testing, not production.
StringList *paramList = strLstNewSplitZ(strCat(strNew("pgbackrest|"), parseParam), "|");
// Don't use cfgLoad() because it has a lot of side effects that we don't want
configParse(strLstSize(paramList), strLstPtr(paramList));
cfgExeSet(strNew(backrestBin));
cfgLoadUpdateOption();
String *result = perlOptionJson();
RETVAL = newSV(strSize(result));
SvPOK_only(RETVAL);
strcpy(SvPV_nolen(RETVAL), strPtr(result));
SvCUR_set(RETVAL, strSize(result));
}
ERROR_XS_END()
OUTPUT:
RETVAL