From 2ace6416a787355df1adc035a6fb571b9f037666 Mon Sep 17 00:00:00 2001 From: TapTap Date: Thu, 3 Sep 2026 22:29:40 +0200 Subject: [PATCH] test: cover configured fsync save path --- README.md | 2 +- tests/test_file.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fdbd9f3..6962093 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,7 @@ defaults to the current directory. | ## Protocol and Security -FastSync protocol version `2.2.0` is shared by the client and server. The +FastSync protocol version `2.3.0` is shared by the client and server. The current protocol is sender-driven and includes configuration negotiation, incremental checks, checksums, manifests, keep-alives, abort handling, and FastSync-native delta messages. Client and server versions must currently diff --git a/tests/test_file.c b/tests/test_file.c index a0fa1f7..d9e492b 100644 --- a/tests/test_file.c +++ b/tests/test_file.c @@ -1,6 +1,7 @@ #include "test_file.h" #include "file.h" #include "data.h" +#include "config.h" #include "utils.h" #include "protocol.h" #include "test_utils.h" @@ -88,6 +89,30 @@ static void test_file_save_to_disk() { rmdir("test_save_tmp"); } +static void test_file_save_to_disk_with_fsync_config() { + File* f = file_create("saved_file_fsync.txt"); + EXPECT_NOT_NULL(f); + const char* content = "Save to disk with fsync"; + f->data->data = malloc(strlen(content)); + EXPECT_NOT_NULL(f->data->data); + memcpy(f->data->data, content, strlen(content)); + f->data->size = strlen(content); + + Config* config = config_create(); + EXPECT_NOT_NULL(config); + config->use_fsync = true; + EXPECT_TRUE(file_save_to_disk("test_save_fsync_tmp", f, config)); + + struct stat st; + EXPECT_EQ_INT(stat("test_save_fsync_tmp/saved_file_fsync.txt", &st), 0); + EXPECT_EQ_INT((int)st.st_size, (int)strlen(content)); + + file_destroy(f); + config_delete(config); + unlink("test_save_fsync_tmp/saved_file_fsync.txt"); + rmdir("test_save_fsync_tmp"); +} + static void test_file_write_to_disk_basic() { const char* content = "Basic file_write_to_disk test"; EXPECT_TRUE(file_write_to_disk("test_file_write_to_disk_basic.txt", content, strlen(content), @@ -469,6 +494,7 @@ void test_file() { test_file_load_data(); test_file_load_data_missing_file(); test_file_save_to_disk(); + test_file_save_to_disk_with_fsync_config(); test_file_write_to_disk_basic(); test_file_write_to_disk_with_fsync(); test_file_write_to_disk_creates_dirs();