mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-03 14:52:21 +02:00
Add HRN_STORAGE_TIME() harness macro.
Makes updating the time of a path/file more streamlined in tests. Also update all tests where utime() was being used directly.
This commit is contained in:
parent
3c85a497a6
commit
e07040c2e4
@ -5,6 +5,7 @@ Storage Test Harness
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "common/crypto/cipherBlock.h"
|
||||
#include "common/debug.h"
|
||||
@ -310,3 +311,22 @@ hrnStoragePutLog(const Storage *storage, const char *file, const Buffer *buffer,
|
||||
|
||||
return strZ(log);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
hrnStorageTime(const int line, const Storage *const storage, const char *const path, const time_t modified)
|
||||
{
|
||||
hrnTestLogPrefix(line, true);
|
||||
hrnTestResultBegin(__func__, line, false);
|
||||
|
||||
const char *const pathFull = strZ(storagePathP(storage, path == NULL ? NULL : STR(path)));
|
||||
|
||||
printf("time '%" PRId64 "' on '%s'\n", (int64_t)modified, pathFull);
|
||||
fflush(stdout);
|
||||
|
||||
THROW_ON_SYS_ERROR_FMT(
|
||||
utime(pathFull, &((struct utimbuf){.actime = modified, .modtime = modified})) == -1, FileInfoError,
|
||||
"unable to set time for '%s'", pathFull);
|
||||
|
||||
hrnTestResultEnd();
|
||||
}
|
||||
|
@ -99,6 +99,14 @@ Remove a file and error if it does not exist
|
||||
TEST_RESULT_VOID(storageRemoveP(storage, STR(path), .errorOnMissing = true), "remove file '%s'", \
|
||||
strZ(storagePathP(storage, STR(path))))
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Change the time of a path/file
|
||||
***********************************************************************************************************************************/
|
||||
#define HRN_STORAGE_TIME(storage, path, time) \
|
||||
hrnStorageTime(__LINE__, storage, path, time)
|
||||
|
||||
void hrnStorageTime(const int line, const Storage *const storage, const char *const path, const time_t modified);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Dummy interface for constructing test storage drivers. All required functions are stubbed out so this interface can be copied and
|
||||
specific functions replaced for testing.
|
||||
|
@ -1,8 +1,6 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Backup Command
|
||||
***********************************************************************************************************************************/
|
||||
#include <utime.h>
|
||||
|
||||
#include "command/stanza/create.h"
|
||||
#include "command/stanza/upgrade.h"
|
||||
#include "common/crypto/hash.h"
|
||||
@ -2571,11 +2569,7 @@ testRun(void)
|
||||
harnessCfgLoad(cfgCmdBackup, argList);
|
||||
|
||||
// Update pg_control timestamp
|
||||
THROW_ON_SYS_ERROR(
|
||||
utime(
|
||||
strZ(storagePathP(storagePg(), STRDEF("global/pg_control"))),
|
||||
&(struct utimbuf){.actime = backupTimeStart, .modtime = backupTimeStart}) != 0, FileWriteError,
|
||||
"unable to set time");
|
||||
HRN_STORAGE_TIME(storagePg(), "global/pg_control", backupTimeStart);
|
||||
|
||||
// Run backup. Make sure that the timeline selected converts to hexdecimal that can't be interpreted as decimal.
|
||||
testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .timeline = 0x2C);
|
||||
|
@ -1,9 +1,6 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Posix Storage
|
||||
***********************************************************************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "common/io/io.h"
|
||||
#include "common/time.h"
|
||||
#include "storage/read.h"
|
||||
@ -204,8 +201,7 @@ testRun(void)
|
||||
"path not enforced");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000};
|
||||
THROW_ON_SYS_ERROR_FMT(utime(testPath(), &utimeTest) != 0, FileWriteError, "unable to set time for '%s'", testPath());
|
||||
HRN_STORAGE_TIME(storageTest, testPath(), 1555160000);
|
||||
|
||||
TEST_ASSIGN(info, storageInfoP(storageTest, strNew(testPath())), "get path info");
|
||||
TEST_RESULT_STR(info.name, NULL, " name is not set");
|
||||
@ -224,8 +220,7 @@ testRun(void)
|
||||
const Buffer *buffer = BUFSTRDEF("TESTFILE");
|
||||
TEST_RESULT_VOID(storagePutP(storageNewWriteP(storageTest, fileName), buffer), "put test file");
|
||||
|
||||
utimeTest.modtime = 1555155555;
|
||||
THROW_ON_SYS_ERROR_FMT(utime(strZ(fileName), &utimeTest) != 0, FileWriteError, "unable to set time for '%s'", testPath());
|
||||
HRN_STORAGE_TIME(storageTest, strZ(fileName), 1555155555);
|
||||
|
||||
#ifdef TEST_CONTAINER_REQUIRED
|
||||
TEST_RESULT_INT(system(strZ(strNewFmt("sudo chown 99999:99999 %s", strZ(fileName)))), 0, "set invalid user/group");
|
||||
|
@ -1,8 +1,6 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Remote Storage
|
||||
***********************************************************************************************************************************/
|
||||
#include <utime.h>
|
||||
|
||||
#include "command/backup/pageChecksum.h"
|
||||
#include "common/crypto/cipherBlock.h"
|
||||
#include "common/io/bufferRead.h"
|
||||
@ -98,9 +96,7 @@ testRun(void)
|
||||
TEST_TITLE("path info");
|
||||
|
||||
storagePathCreateP(storageTest, strNew("repo"));
|
||||
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000};
|
||||
THROW_ON_SYS_ERROR(
|
||||
utime(strZ(storagePathP(storageTest, strNew("repo"))), &utimeTest) != 0, FileWriteError, "unable to set time");
|
||||
HRN_STORAGE_TIME(storageTest, "repo", 1555160000);
|
||||
|
||||
StorageInfo info = {.exists = false};
|
||||
TEST_ASSIGN(info, storageInfoP(storageRemote, NULL), "valid path");
|
||||
@ -278,8 +274,7 @@ testRun(void)
|
||||
storagePutP(storageNewWriteP(storageRemote, strNew("test"), .timeModified = 1555160001), BUFSTRDEF("TESTME"));
|
||||
|
||||
// Path timestamp must be set after file is created since file creation updates it
|
||||
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000};
|
||||
THROW_ON_SYS_ERROR(utime(strZ(storagePathP(storageRemote, NULL)), &utimeTest) != 0, FileWriteError, "unable to set time");
|
||||
HRN_STORAGE_TIME(storageRemote, NULL, 1555160000);
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageInfoListP(storageRemote, NULL, hrnStorageInfoListCallback, &callbackData, .sortOrder = sortOrderAsc),
|
||||
@ -298,8 +293,7 @@ testRun(void)
|
||||
storageRemoveP(storageRemote, STRDEF("test"), .errorOnMissing = true);
|
||||
|
||||
// Path timestamp must be set after file is removed since file removal updates it
|
||||
utimeTest = (struct utimbuf){.actime = 1000000000, .modtime = 1555160000};
|
||||
THROW_ON_SYS_ERROR(utime(strZ(storagePathP(storageRemote, NULL)), &utimeTest) != 0, FileWriteError, "unable to set time");
|
||||
HRN_STORAGE_TIME(storageRemote, NULL, 1555160000);
|
||||
|
||||
VariantList *paramList = varLstNew();
|
||||
varLstAdd(paramList, varNewStrZ(hrnReplaceKey("{[path]}/repo")));
|
||||
|
Loading…
x
Reference in New Issue
Block a user