Skip to content

Commit

Permalink
Remove unit test for the compareJobsDocument and make it private
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Nov 12, 2024
1 parent 8235bd3 commit 8fad21a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 104 deletions.
43 changes: 0 additions & 43 deletions source/jobs/JobsFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,48 +565,11 @@ bool JobsFeature::compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aw
if (count1 != count2) {
return false;
}

std::cout << "Processed str1: " << str1 << std::endl;
std::cout << "Processed str2: " << str2 << std::endl;

return str1 == str2;
}
bool JobsFeature::isDuplicateNotification(JobExecutionData job)
{
unique_lock<mutex> readLatestNotificationLock(latestJobsNotificationLock);

// Basic logging at the start of the function
std::cout << "DEBUG: Entering isDuplicateNotification function" << std::endl;



// Log Job IDs being compared
std::cout << "INFO: Comparing Job IDs - New: " << (job.JobId.has_value() ? job.JobId.value().c_str() : "NULL")
<< ", Latest: " << (latestJobsNotification.JobId.has_value() ? latestJobsNotification.JobId.value().c_str() : "NULL") << std::endl;





// Log Job Documents being compared
std::cout << "INFO: Comparing Job Documents - New: "
<< (job.JobDocument.has_value() ? job.JobDocument.value().View().WriteCompact().c_str() : "NULL")
<< ", Latest: "
<< (latestJobsNotification.JobDocument.has_value() ? latestJobsNotification.JobDocument.value().View().WriteCompact().c_str() : "NULL")
<< std::endl;





// Log Execution Numbers being compared
std::cout << "INFO: Comparing Execution Numbers - New: "
<< (job.ExecutionNumber.has_value() ? std::to_string(job.ExecutionNumber.value()) : "NULL")
<< ", Latest: "
<< (latestJobsNotification.ExecutionNumber.has_value() ? std::to_string(latestJobsNotification.ExecutionNumber.value()) : "NULL")
<< std::endl;



if (!latestJobsNotification.JobId.has_value())
{
Expand All @@ -628,12 +591,6 @@ bool JobsFeature::isDuplicateNotification(JobExecutionData job)
return false;
}

std::cout << "INFO: Comparing Job Documents after replacement - New: "
<< (job.JobDocument.has_value() ? job.JobDocument.value().View().WriteCompact().c_str() : "NULL")
<< ", Latest: "
<< (latestJobsNotification.JobDocument.has_value() ? latestJobsNotification.JobDocument.value().View().WriteCompact().c_str() : "NULL")
<< std::endl;

if (job.ExecutionNumber.value() != latestJobsNotification.ExecutionNumber.value())
{
LOG_DEBUG(TAG, "Execution number differs");
Expand Down
9 changes: 3 additions & 6 deletions source/jobs/JobsFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ namespace Aws
virtual int stop() override;

protected:

bool compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aws::Crt::JsonObject& job2);

/**
* \brief Begins running the Jobs feature
*/
Expand Down Expand Up @@ -324,9 +321,9 @@ namespace Aws
* @param job2 The second job document as a JsonObject
* @return true if the documents are equivalent (ignoring pre-signed URLs), false otherwise
*/
// Add this line to declare the test class as a friend
friend class TestJobsFeaturePrivate;

bool compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aws::Crt::JsonObject& job2);


/**
* \brief Stores information about a job notification
Expand Down
55 changes: 0 additions & 55 deletions test/jobs/TestJobsFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,25 +281,6 @@ class TestJobsFeature : public ::testing::Test
shared_ptr<MockJobEngine> mockEngine;
};

class TestJobsFeaturePrivate : public ::testing::Test, public JobsFeature
{
protected:
Aws::Crt::ApiHandle apiHandle;
std::unique_ptr<JobsFeature> jobsFeature;

void SetUp() override
{
// The ApiHandle constructor initializes the AWS CRT library
jobsFeature.reset(new JobsFeature());
}

void TearDown() override
{
jobsFeature.reset();
// The ApiHandle destructor cleans up the AWS CRT library
}
};

MATCHER_P(ThingNameEq, ThingName, "Matcher ThingName for all Aws request Objects using Aws::Crt::String")
{
return arg.ThingName.value() == ThingName;
Expand Down Expand Up @@ -729,40 +710,4 @@ TEST_F(TestJobsFeature, InvalidJobDocument)

jobsMock->init(std::shared_ptr<Mqtt::MqttConnection>(), notifier, config);
jobsMock->invokeRunJobs();
}

TEST_F(TestJobsFeaturePrivate, CompareJobDocuments)
{
// Test case 1: Identical documents
Aws::Crt::JsonObject doc1("{\"key\": \"value\"}");
Aws::Crt::JsonObject doc2("{\"key\": \"value\"}");
EXPECT_TRUE(compareJobDocuments(doc1, doc2));

// Test case 2: Different documents
Aws::Crt::JsonObject doc3("{\"key\": \"different_value\"}");
EXPECT_FALSE(compareJobDocuments(doc1, doc3));

// Test case 3: Documents with pre-signed URLs
Aws::Crt::JsonObject doc4("{\"url\": \"https://bucket.s3.amazonaws.com/file?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1234567890&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX\"}");
Aws::Crt::JsonObject doc5("{\"url\": \"https://bucket.s3.amazonaws.com/file?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=9876543210&Signature=YYYYYYYYYYYYYYYYYYYYYYYYYYY\"}");
EXPECT_TRUE(compareJobDocuments(doc4, doc5));

// Test case 4: Documents with multiple pre-signed URLs
Aws::Crt::JsonObject doc6("{\"url1\": \"https://bucket1.s3.amazonaws.com/file1?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1234567890&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX\", \"url2\": \"https://bucket2.s3.amazonaws.com/file2?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1234567890&Signature=ZZZZZZZZZZZZZZZZZZZZZZZZZZZ\"}");
Aws::Crt::JsonObject doc7("{\"url1\": \"https://bucket1.s3.amazonaws.com/file1?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=9876543210&Signature=YYYYYYYYYYYYYYYYYYYYYYYYYYY\", \"url2\": \"https://bucket2.s3.amazonaws.com/file2?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=9876543210&Signature=WWWWWWWWWWWWWWWWWWWWWWWWWWW\"}");
EXPECT_TRUE(compareJobDocuments(doc6, doc7));

// Test case 6: Documents with multiple pre-signed URLs in one doc and single url in the other
Aws::Crt::JsonObject doc8("{\"url1\": \"https://bucket1.s3.amazonaws.com/file1?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=9876543210&Signature=YYYYYYYYYYYYYYYYYYYYYYYYYYY\"}");
EXPECT_FALSE(compareJobDocuments(doc6, doc8));

// Test case 7: Documents with different structure
Aws::Crt::JsonObject doc9("{\"key1\": \"value1\", \"key2\": \"value2\"}");
Aws::Crt::JsonObject doc10("{\"key1\": \"value1\", \"key3\": \"value3\"}");
EXPECT_FALSE(compareJobDocuments(doc9, doc10));

// Test case 8: Documents with same pre-signed URLs but different buckets
Aws::Crt::JsonObject doc11("{\"url\": \"https://bucket1.s3.amazonaws.com/file?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1234567890&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX\"}");
Aws::Crt::JsonObject doc12("{\"url\": \"https://bucket2.s3.amazonaws.com/file?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1234567890&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX\"}");
EXPECT_FALSE(compareJobDocuments(doc11, doc12));
}

0 comments on commit 8fad21a

Please sign in to comment.