Skip to content

Commit

Permalink
use fixed system time in test mode to have fixed test output
Browse files Browse the repository at this point in the history
fixes test suite regression from previous commit
  • Loading branch information
fabled committed Jun 3, 2019
1 parent 37fbafc commit 1c47f37
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
return -1;

time(&now);
now = apk_time();
localtime_r(&now, &tm);
strftime(ver, sizeof ver, "%Y%m%d.%H%M%S", &tm);

Expand Down
9 changes: 9 additions & 0 deletions src/apk.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ static struct apk_string_array *test_repos;

char **apk_argv;

time_t apk_time(void)
{
#ifdef TEST_MODE
return 1559567666;
#else
return time(NULL);
#endif
}

static void version(void)
{
printf("apk-tools " APK_VERSION ", compiled for " APK_DEFAULT_ARCH ".\n"
Expand Down
3 changes: 3 additions & 0 deletions src/apk_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <endian.h>
#include <string.h>
#include <time.h>

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BIT(x) (1 << (x))
Expand Down Expand Up @@ -121,6 +122,8 @@ extern char **apk_argv;
#define APK_MAX_TAGS 16 /* see solver; unsigned short */
#define APK_CACHE_CSUM_BYTES 4

time_t apk_time(void);

static inline size_t apk_calc_installed_size(size_t size)
{
const size_t bsize = 4 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion src/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.gid, ae->gid);
PUT_OCTAL(buf.mode, ae->mode & 07777);
PUT_OCTAL(buf.mtime, ae->mtime ?: time(NULL));
PUT_OCTAL(buf.mtime, ae->mtime ?: apk_time());

/* Checksum */
strcpy(buf.magic, "ustar ");
Expand Down
4 changes: 2 additions & 2 deletions src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
char tmpcacheitem[128], *cacheitem = &tmpcacheitem[tmpprefix.len];
apk_blob_t b = APK_BLOB_BUF(tmpcacheitem);
int r, fd;
time_t now = time(NULL);
time_t now = apk_time();

apk_blob_push_blob(&b, tmpprefix);
if (pkg != NULL)
Expand Down Expand Up @@ -1005,7 +1005,7 @@ static int apk_db_scriptdb_write(struct apk_database *db, struct apk_ostream *os
char filename[256];
apk_blob_t bfn;
int r, i;
time_t now = time(NULL);
time_t now = apk_time();

list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) {
pkg = ipkg->pkg;
Expand Down
2 changes: 1 addition & 1 deletion test/basic8.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
--no-network
add -t .virtual
@EXPECT
(1/1) Installing .virtual (0)
(1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 0 packages
2 changes: 1 addition & 1 deletion test/basic9.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
--test-world a
add -t .virtual a
@EXPECT
(1/1) Installing .virtual (0)
(1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 2 packages

0 comments on commit 1c47f37

Please sign in to comment.