use fixed system time in test mode to have fixed test output

fixes test suite regression from previous commit
cute-signatures
Timo Teräs 2019-06-03 16:18:29 +03:00
parent 37fbafcd92
commit 1c47f37443
7 changed files with 18 additions and 6 deletions

View File

@ -108,7 +108,7 @@ static int add_main(void *ctx, struct apk_database *db, struct apk_string_array
if (virtdep.name->name[0] != '.' && non_repository_check(db)) if (virtdep.name->name[0] != '.' && non_repository_check(db))
return -1; return -1;
time(&now); now = apk_time();
localtime_r(&now, &tm); localtime_r(&now, &tm);
strftime(ver, sizeof ver, "%Y%m%d.%H%M%S", &tm); strftime(ver, sizeof ver, "%Y%m%d.%H%M%S", &tm);

View File

@ -47,6 +47,15 @@ static struct apk_string_array *test_repos;
char **apk_argv; char **apk_argv;
time_t apk_time(void)
{
#ifdef TEST_MODE
return 1559567666;
#else
return time(NULL);
#endif
}
static void version(void) static void version(void)
{ {
printf("apk-tools " APK_VERSION ", compiled for " APK_DEFAULT_ARCH ".\n" printf("apk-tools " APK_VERSION ", compiled for " APK_DEFAULT_ARCH ".\n"

View File

@ -14,6 +14,7 @@
#include <endian.h> #include <endian.h>
#include <string.h> #include <string.h>
#include <time.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BIT(x) (1 << (x)) #define BIT(x) (1 << (x))
@ -121,6 +122,8 @@ extern char **apk_argv;
#define APK_MAX_TAGS 16 /* see solver; unsigned short */ #define APK_MAX_TAGS 16 /* see solver; unsigned short */
#define APK_CACHE_CSUM_BYTES 4 #define APK_CACHE_CSUM_BYTES 4
time_t apk_time(void);
static inline size_t apk_calc_installed_size(size_t size) static inline size_t apk_calc_installed_size(size_t size)
{ {
const size_t bsize = 4 * 1024; const size_t bsize = 4 * 1024;

View File

@ -396,7 +396,7 @@ int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae,
PUT_OCTAL(buf.uid, ae->uid); PUT_OCTAL(buf.uid, ae->uid);
PUT_OCTAL(buf.gid, ae->gid); PUT_OCTAL(buf.gid, ae->gid);
PUT_OCTAL(buf.mode, ae->mode & 07777); PUT_OCTAL(buf.mode, ae->mode & 07777);
PUT_OCTAL(buf.mtime, ae->mtime ?: time(NULL)); PUT_OCTAL(buf.mtime, ae->mtime ?: apk_time());
/* Checksum */ /* Checksum */
strcpy(buf.magic, "ustar "); strcpy(buf.magic, "ustar ");

View File

@ -624,7 +624,7 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
char tmpcacheitem[128], *cacheitem = &tmpcacheitem[tmpprefix.len]; char tmpcacheitem[128], *cacheitem = &tmpcacheitem[tmpprefix.len];
apk_blob_t b = APK_BLOB_BUF(tmpcacheitem); apk_blob_t b = APK_BLOB_BUF(tmpcacheitem);
int r, fd; int r, fd;
time_t now = time(NULL); time_t now = apk_time();
apk_blob_push_blob(&b, tmpprefix); apk_blob_push_blob(&b, tmpprefix);
if (pkg != NULL) if (pkg != NULL)
@ -1005,7 +1005,7 @@ static int apk_db_scriptdb_write(struct apk_database *db, struct apk_ostream *os
char filename[256]; char filename[256];
apk_blob_t bfn; apk_blob_t bfn;
int r, i; int r, i;
time_t now = time(NULL); time_t now = apk_time();
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) { list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) {
pkg = ipkg->pkg; pkg = ipkg->pkg;

View File

@ -2,5 +2,5 @@
--no-network --no-network
add -t .virtual add -t .virtual
@EXPECT @EXPECT
(1/1) Installing .virtual (0) (1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 0 packages OK: 0 MiB in 0 packages

View File

@ -4,5 +4,5 @@
--test-world a --test-world a
add -t .virtual a add -t .virtual a
@EXPECT @EXPECT
(1/1) Installing .virtual (0) (1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 2 packages OK: 0 MiB in 2 packages