Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlaa Eddine Elamri <alaeddine.elamri@bareos.com>2022-08-19 19:43:25 +0300
committerPhilipp Storz <philipp.storz@bareos.com>2022-09-19 11:49:51 +0300
commit53d4107e50809b63c7ebe65c419ab958f3a99448 (patch)
tree24db09a03dde0f993d348abadc02a8802d31ed39
parent964074819ce4ce38e16cc18431b75ec84ed1050b (diff)
adding test and renaming
-rw-r--r--core/src/dird/ua_purge.cc7
-rw-r--r--core/src/dird/ua_purge.h2
-rw-r--r--core/src/tests/CMakeLists.txt6
-rw-r--r--core/src/tests/pruning.cc26
4 files changed, 33 insertions, 8 deletions
diff --git a/core/src/dird/ua_purge.cc b/core/src/dird/ua_purge.cc
index cb80d0524..8a2fccd4a 100644
--- a/core/src/dird/ua_purge.cc
+++ b/core/src/dird/ua_purge.cc
@@ -314,8 +314,7 @@ void PurgeFilesFromJobs(UaContext* ua, const char* jobs)
ua->db->PurgeFiles(jobs);
}
-static std::string TransformJobidsTobedeleted(UaContext* ua,
- std::vector<JobId_t>& del)
+std::string PrepareJobidsTobedeleted(UaContext* ua, std::vector<JobId_t>& del)
{
std::sort(del.begin(), del.end());
@@ -340,7 +339,7 @@ void PurgeJobListFromCatalog(UaContext* ua, std::vector<JobId_t>& del)
{
Dmsg1(150, "num_ids=%d\n", del.size());
- std::string jobids_to_delete = TransformJobidsTobedeleted(ua, del);
+ std::string jobids_to_delete = PrepareJobidsTobedeleted(ua, del);
ua->SendMsg(_("Purging the following JobIds: %s\n"),
jobids_to_delete.c_str());
PurgeJobsFromCatalog(ua, jobids_to_delete.c_str());
@@ -352,7 +351,7 @@ void PurgeJobListFromCatalog(UaContext* ua, std::vector<JobId_t>& del)
*/
void PurgeFilesFromJobList(UaContext* ua, std::vector<JobId_t>& del)
{
- std::string jobids_to_delete = TransformJobidsTobedeleted(ua, del);
+ std::string jobids_to_delete = PrepareJobidsTobedeleted(ua, del);
PurgeFilesFromJobs(ua, jobids_to_delete.c_str());
}
diff --git a/core/src/dird/ua_purge.h b/core/src/dird/ua_purge.h
index 7c5bdff9d..fb7cef770 100644
--- a/core/src/dird/ua_purge.h
+++ b/core/src/dird/ua_purge.h
@@ -34,6 +34,8 @@ void PurgeFilesFromJobs(UaContext* ua, const char* jobs);
void PurgeJobsFromCatalog(UaContext* ua, const char* jobs);
void PurgeJobListFromCatalog(UaContext* ua, std::vector<JobId_t>& del);
void PurgeFilesFromJobList(UaContext* ua, std::vector<JobId_t>& del);
+std::string PrepareJobidsTobedeleted(UaContext* ua,
+ std::vector<JobId_t>& del);
} /* namespace directordaemon */
#endif // BAREOS_DIRD_UA_PURGE_H_
diff --git a/core/src/tests/CMakeLists.txt b/core/src/tests/CMakeLists.txt
index 16e7bee3b..381cfba01 100644
--- a/core/src/tests/CMakeLists.txt
+++ b/core/src/tests/CMakeLists.txt
@@ -213,9 +213,9 @@ if(NOT client-only)
LINK_LIBRARIES ${LINK_LIBRARIES}
)
-bareos_add_test(
- pruning LINK_LIBRARIES testing_common GTest::gtest_main
-)
+ bareos_add_test(
+ pruning LINK_LIBRARIES testing_common GTest::gtest_main
+ )
bareos_add_test(
runjob LINK_LIBRARIES dird_objects bareosfind bareossql GTest::gtest_main
)
diff --git a/core/src/tests/pruning.cc b/core/src/tests/pruning.cc
index 401d4986c..2c095af7f 100644
--- a/core/src/tests/pruning.cc
+++ b/core/src/tests/pruning.cc
@@ -24,9 +24,11 @@
#include "include/jcr.h"
#include "dird/job.h"
#include "dird/ua_prune.h"
+#include "dird/ua_purge.h"
TEST(Pruning, ExcludeRunningJobsFromList)
{
+ InitDirGlobals();
std::string path_to_config
= std::string(RELATIVE_PROJECT_SOURCE_DIR "/configs/pruning/");
PConfigParser director_config(DirectorPrepareResources(path_to_config));
@@ -39,7 +41,7 @@ TEST(Pruning, ExcludeRunningJobsFromList)
JobControlRecord* jcr3 = directordaemon::NewDirectorJcr();
jcr3->JobId = 3;
- std::vector<JobId_t> pruninglist{1, 2, 3, 4, 5};
+ std::vector<JobId_t> pruninglist{0, 0, 1, 2, 3, 4, 5};
int NumJobsToBePruned
= directordaemon::ExcludeRunningJobsFromList(pruninglist);
@@ -47,3 +49,25 @@ TEST(Pruning, ExcludeRunningJobsFromList)
EXPECT_EQ(pruninglist[0], 4);
EXPECT_EQ(pruninglist[1], 5);
}
+
+TEST(Pruning, TransformJobidsTobedeleted)
+{
+ InitDirGlobals();
+ std::string path_to_config
+ = std::string(RELATIVE_PROJECT_SOURCE_DIR "/configs/pruning/");
+ PConfigParser director_config(DirectorPrepareResources(path_to_config));
+ if (!director_config) { return; }
+
+ JobControlRecord* jcr1 = directordaemon::NewDirectorJcr();
+ jcr1->JobId = 1;
+
+ directordaemon::UaContext* ua = directordaemon::new_ua_context(jcr1);
+ std::vector<JobId_t> pruninglist{0, 1, 2, 0, 3, 4, 5};
+ std::string jobids_to_delete
+ = directordaemon::PrepareJobidsTobedeleted(ua, pruninglist);
+
+ EXPECT_EQ(jobids_to_delete, "2,3,4,5");
+ EXPECT_EQ(pruninglist.size(), 4);
+
+ FreeUaContext(ua);
+}