Skip to content

Commit 8199925

Browse files
Merge pull request #7 from harsh-agarwal1/dest
DataSync: Config: Added DestinationPath to configuration
2 parents d92ff1e + c1b319b commit 8199925

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

config/schema/example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
{
1212
"Path": "/file2/path/to/sync",
13+
"DestinationPath": "/file2/path/to/target/destination",
1314
"Description": "Add details about the data and purpose of the synchronization",
1415
"SyncDirection": "Bidirectional",
1516
"SyncType": "Periodic",

config/schema/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"Path": {
4242
"$ref": "#/$defs/path"
4343
},
44+
"DestinationPath": {
45+
"$ref": "#/$defs/destinationPath"
46+
},
4447
"Description": {
4548
"$ref": "#/$defs/description"
4649
},
@@ -74,6 +77,9 @@
7477
"Path": {
7578
"$ref": "#/$defs/path"
7679
},
80+
"DestinationPath": {
81+
"$ref": "#/$defs/destinationPath"
82+
},
7783
"Description": {
7884
"$ref": "#/$defs/description"
7985
},
@@ -110,6 +116,10 @@
110116
"description": "Absolute path of the file/directory to be synced",
111117
"$ref": "#/$defs/rootFilePath"
112118
},
119+
"destinationPath": {
120+
"description": "Absolute path to the destination file/directory to be synced",
121+
"$ref": "#/$defs/rootFilePath"
122+
},
113123
"description": {
114124
"description": "A short description about the file/directory to be synced",
115125
"type": "string"

src/data_sync_config.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ DataSyncConfig::DataSyncConfig(const nlohmann::json& config) :
3131
.value_or(SyncType::Immediate))
3232
{
3333
// Initiailze optional members
34+
if (config.contains("DestinationPath"))
35+
{
36+
_destPath = config["DestinationPath"].get<std::string>();
37+
}
38+
else
39+
{
40+
_destPath = std::nullopt;
41+
}
42+
3443
if (_syncType == SyncType::Periodic)
3544
{
3645
constexpr auto defPeriodicity = 60;
@@ -80,6 +89,7 @@ bool DataSyncConfig::operator==(const DataSyncConfig& dataSyncCfg) const
8089
{
8190
return _path == dataSyncCfg._path &&
8291
_syncDirection == dataSyncCfg._syncDirection &&
92+
_destPath == dataSyncCfg._destPath &&
8393
_syncType == dataSyncCfg._syncType &&
8494
_periodicityInSec == dataSyncCfg._periodicityInSec &&
8595
_retry == dataSyncCfg._retry &&

src/data_sync_config.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ struct DataSyncConfig
132132
*/
133133
std::string _path;
134134

135+
/**
136+
* @brief The file or directory path to the destination to be synchronized.
137+
*/
138+
std::optional<std::string> _destPath;
139+
135140
/**
136141
* @brief Used to get sync direction.
137142
*/

test/data_sync_config_test.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ TEST(DataSyncConfigParserTest, TestImmediateFileSyncWithNoRetry)
3434
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
3535

3636
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
37+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
3738
EXPECT_EQ(dataSyncConfig._syncDirection,
3839
data_sync::config::SyncDirection::Active2Passive);
3940
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);
@@ -66,6 +67,7 @@ TEST(DataSyncConfigParserTest, TestPeriodicFileSyncWithRetry)
6667
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
6768

6869
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
70+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
6971
EXPECT_EQ(dataSyncConfig._syncDirection,
7072
data_sync::config::SyncDirection::Passive2Active);
7173
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Periodic);
@@ -97,6 +99,7 @@ TEST(DataSyncConfigParserTest, TestImmediateDirectorySyncWithNoRetry)
9799
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
98100

99101
EXPECT_EQ(dataSyncConfig._path, "/directory/path/to/sync");
102+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
100103
EXPECT_EQ(dataSyncConfig._syncDirection,
101104
data_sync::config::SyncDirection::Passive2Active);
102105
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);
@@ -127,6 +130,7 @@ TEST(DataSyncConfigParserTest, TestImmediateAndBidirectionalDirectorySync)
127130
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
128131

129132
EXPECT_EQ(dataSyncConfig._path, "/directory/path/to/sync");
133+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
130134
EXPECT_EQ(dataSyncConfig._syncDirection,
131135
data_sync::config::SyncDirection::Bidirectional);
132136
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);
@@ -160,6 +164,7 @@ TEST(DataSyncConfigParserTest, TestFileSyncWithInvalidPeriodicity)
160164
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
161165

162166
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
167+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
163168
EXPECT_EQ(dataSyncConfig._syncDirection,
164169
data_sync::config::SyncDirection::Active2Passive);
165170
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Periodic);
@@ -195,6 +200,7 @@ TEST(DataSyncConfigParserTest, TestFileSyncWithInvalidRetryInterval)
195200
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
196201

197202
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
203+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
198204
EXPECT_EQ(dataSyncConfig._syncDirection,
199205
data_sync::config::SyncDirection::Active2Passive);
200206
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Periodic);
@@ -227,6 +233,7 @@ TEST(DataSyncConfigParserTest, TestFileSyncWithInvalidSyncDirection)
227233
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
228234

229235
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
236+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
230237
EXPECT_EQ(dataSyncConfig._syncDirection,
231238
data_sync::config::SyncDirection::Active2Passive);
232239
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);
@@ -257,6 +264,39 @@ TEST(DataSyncConfigParserTest, TestFileSyncWithInvalidSyncType)
257264
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
258265

259266
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
267+
EXPECT_EQ(dataSyncConfig._destPath, std::nullopt);
268+
EXPECT_EQ(dataSyncConfig._syncDirection,
269+
data_sync::config::SyncDirection::Active2Passive);
270+
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);
271+
EXPECT_EQ(dataSyncConfig._periodicityInSec, std::nullopt);
272+
EXPECT_EQ(dataSyncConfig._retry, std::nullopt);
273+
EXPECT_EQ(dataSyncConfig._excludeFileList, std::nullopt);
274+
EXPECT_EQ(dataSyncConfig._includeFileList, std::nullopt);
275+
}
276+
277+
/*
278+
* Test when the input JSON contains the details of the file to be synced
279+
* immediately with valid Destination and no overriding retry attempt and
280+
* retry interval.
281+
*/
282+
TEST(DataSyncConfigParserTest, TestFileSyncWithValidDestination)
283+
{
284+
// JSON object with details of file to be synced.
285+
const auto configJSON = R"(
286+
{
287+
"Path": "/file/path/to/sync",
288+
"DestinationPath": "/file/path/to/destination",
289+
"Description": "Add details about the data and purpose of the synchronization",
290+
"SyncDirection": "Active2Passive",
291+
"SyncType": "Immediate"
292+
}
293+
294+
)"_json;
295+
296+
data_sync::config::DataSyncConfig dataSyncConfig(configJSON);
297+
298+
EXPECT_EQ(dataSyncConfig._path, "/file/path/to/sync");
299+
EXPECT_EQ(dataSyncConfig._destPath, "/file/path/to/destination");
260300
EXPECT_EQ(dataSyncConfig._syncDirection,
261301
data_sync::config::SyncDirection::Active2Passive);
262302
EXPECT_EQ(dataSyncConfig._syncType, data_sync::config::SyncType::Immediate);

0 commit comments

Comments
 (0)