From 9a5fb6698c710e0a60d3f30d2b529e3bc9b7b6bf Mon Sep 17 00:00:00 2001 From: Rakhi Mundhada Date: Thu, 17 Oct 2024 15:19:51 +0530 Subject: [PATCH] fix test cases --- collectors/googlestackdriver/collector.js | 19 +++++++++---------- collectors/googlestackdriver/test/test.js | 5 ++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/collectors/googlestackdriver/collector.js b/collectors/googlestackdriver/collector.js index e2906047..2b5fbc97 100644 --- a/collectors/googlestackdriver/collector.js +++ b/collectors/googlestackdriver/collector.js @@ -183,17 +183,17 @@ class GooglestackdriverCollector extends PawsCollector { } generateFilter(state) { - const logIds = process.env.paws_collector_param_string_2 ? JSON.parse(process.env.paws_collector_param_string_2) : []; + const logNames = process.env.paws_collector_param_string_2 ? JSON.parse(process.env.paws_collector_param_string_2) : []; const filterConditions = []; let logFilterCondition; - if (logIds.length > 0) { - logIds.forEach(logId => { - const trimmedLogId = logId?.trim(); + if (logNames.length > 0) { + logNames.forEach(logName => { + const trimmedlogName = logName?.trim(); - if (trimmedLogId) { - const encodeLogId = this.isUriEncoded(logId) ? logId : encodeURIComponent(logId); - filterConditions.push(`logName:"${encodeLogId}"`); + if (trimmedlogName) { + const encodelogName = this.isUriEncoded(logName) ? logName : encodeURIComponent(logName); + filterConditions.push(`logName:"${encodelogName}"`); } else { AlLogger.warn("Skipping empty log ID."); } @@ -204,7 +204,6 @@ class GooglestackdriverCollector extends PawsCollector { } // Construct the basic timestamp filter let filterQuery = `timestamp >= "${state.since}" AND timestamp < "${state.until}"`; - if (logFilterCondition) { // Combine the LogName and timesamp filter filterQuery = `${filterQuery} AND (${logFilterCondition})`; @@ -212,8 +211,8 @@ class GooglestackdriverCollector extends PawsCollector { return filterQuery; } - isUriEncoded(logId) { - return decodeURIComponent(logId) !== logId; + isUriEncoded(logName) { + return decodeURIComponent(logName) !== logName; } diff --git a/collectors/googlestackdriver/test/test.js b/collectors/googlestackdriver/test/test.js index 96a8a0d2..be82bc80 100644 --- a/collectors/googlestackdriver/test/test.js +++ b/collectors/googlestackdriver/test/test.js @@ -555,7 +555,7 @@ describe('Unit Tests', function() { const startDate = moment().subtract(20, 'minutes'); let since = startDate.toISOString(); let until = startDate.add(collector.pollInterval, 'seconds').toISOString(); - process.env.paws_collector_param_string_2 = "[\"cloudaudit.googleapis.com%2Factivity\",\"\",\"cloudfunctions.googleapis.com%2Fcloud-functions\"]"; + process.env.paws_collector_param_string_2 = "[\"cloudaudit.googleapis.com%2Factivity\",\"\",\"cloudfunctions.googleapis.com/cloud-functions\"]"; const curState = { since: since, until: until, @@ -563,7 +563,7 @@ describe('Unit Tests', function() { stream: 'projects/imran-49253', }; // Expected filter string - const expectedFilter = `timestamp >= "${since}" AND timestamp < "${until}" AND (logName="projects/imran-49253/logs/cloudaudit.googleapis.com%2Factivity" OR logName="projects/imran-49253/logs/cloudfunctions.googleapis.com%2Fcloud-functions")`; + const expectedFilter = `timestamp >= "${since}" AND timestamp < "${until}" AND (logName:"cloudaudit.googleapis.com%2Factivity" OR logName:"cloudfunctions.googleapis.com%2Fcloud-functions")`; // Call the function to generate the filter const filter = collector.generateFilter(curState); @@ -622,7 +622,6 @@ describe('Unit Tests', function() { const startDate = moment().subtract(20, 'minutes'); let since = startDate.toISOString(); let until = startDate.add(collector.pollInterval, 'seconds').toISOString(); - process.env.paws_collector_param_string_2 = null; const curState = { since: since, until: until,