aws-testing-library
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -10,8 +10,9 @@ "use strict"; | ||
(0, common_1.verifyProps)({ ...props, pattern }, cloudwatch_1.expectedProps); | ||
const { region, function: functionName, startTime = (0, common_1.epochDateMinusHours)(1), } = props; | ||
const { events } = await (0, cloudwatch_2.filterLogEvents)(region, functionName, startTime, pattern); | ||
const { region, function: functionName, startTime = (0, common_1.epochDateMinusHours)(1), logGroupName, } = props; | ||
const { events } = await (0, cloudwatch_2.filterLogEvents)(region, logGroupName || (0, cloudwatch_2.getLogGroupName)(functionName || ''), startTime, pattern); | ||
const found = events.length > 0; | ||
const messageSubject = logGroupName || functionName; | ||
return { | ||
message: `expected ${functionName} to have log matching ${pattern}`, | ||
negateMessage: `expected ${functionName} not to have log matching ${pattern}`, | ||
message: `expected ${messageSubject} to have log matching ${pattern}`, | ||
negateMessage: `expected ${messageSubject} not to have log matching ${pattern}`, | ||
pass: found, | ||
@@ -18,0 +19,0 @@ }; |
import { ICommonProps } from './'; | ||
export interface ICloudwatchProps extends ICommonProps { | ||
function: string; | ||
function?: string; | ||
startTime?: number; | ||
logGroupName?: string; | ||
} | ||
export declare const expectedProps: string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.expectedProps = void 0; | ||
exports.expectedProps = ['region', 'function', 'pattern']; | ||
exports.expectedProps = ['region', 'pattern']; | ||
//# sourceMappingURL=cloudwatch.js.map |
@@ -10,5 +10,5 @@ "use strict"; | ||
(0, index_1.verifyProps)({ ...props, pattern }, cloudwatch_1.expectedProps); | ||
const { region, function: functionName, startTime = (0, index_1.epochDateMinusHours)(1), } = props; | ||
const { region, function: functionName, startTime = (0, index_1.epochDateMinusHours)(1), logGroupName, } = props; | ||
try { | ||
const printFunctionName = this.utils.printExpected(functionName); | ||
const messageSubject = this.utils.printExpected(logGroupName || functionName); | ||
const printRegion = this.utils.printExpected(region); | ||
@@ -18,3 +18,3 @@ const printPattern = this.utils.printExpected(pattern) + os_1.EOL; | ||
const hint = this.utils.matcherHint('.toHaveLog') + os_1.EOL + os_1.EOL; | ||
const { events } = await (0, cloudwatch_2.filterLogEvents)(region, functionName, startTime, pattern); | ||
const { events } = await (0, cloudwatch_2.filterLogEvents)(region, logGroupName || (0, cloudwatch_2.getLogGroupName)(functionName || ''), startTime, pattern); | ||
const found = events.length > 0; | ||
@@ -24,3 +24,3 @@ if (found) { | ||
return { | ||
message: () => `${notHint}Expected ${printFunctionName} at region ${printRegion} not to have log matching pattern ${printPattern}`, | ||
message: () => `${notHint}Expected ${messageSubject} at region ${printRegion} not to have log matching pattern ${printPattern}`, | ||
pass: true, | ||
@@ -32,3 +32,3 @@ }; | ||
return { | ||
message: () => `${hint}Expected ${printFunctionName} at region ${printRegion} to have log matching pattern ${printPattern}`, | ||
message: () => `${hint}Expected ${messageSubject} at region ${printRegion} to have log matching pattern ${printPattern}`, | ||
pass: false, | ||
@@ -35,0 +35,0 @@ }; |
import AWS = require('aws-sdk'); | ||
export declare const filterLogEvents: (region: string, functionName: string, startTime: number, pattern: string) => Promise<{ | ||
export declare const getLogGroupName: (functionName: string) => string; | ||
export declare const filterLogEvents: (region: string, logGroupName: string, startTime: number, pattern: string) => Promise<{ | ||
events: AWS.CloudWatchLogs.FilteredLogEvents; | ||
}>; | ||
export declare const deleteAllLogs: (region: string, functionName: string) => Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deleteAllLogs = exports.filterLogEvents = void 0; | ||
exports.deleteAllLogs = exports.filterLogEvents = exports.getLogGroupName = void 0; | ||
const AWS = require("aws-sdk"); | ||
const getLogGroupName = (functionName) => `/aws/lambda/${functionName}`; | ||
const filterLogEvents = async (region, functionName, startTime, pattern) => { | ||
exports.getLogGroupName = getLogGroupName; | ||
const filterLogEvents = async (region, logGroupName, startTime, pattern) => { | ||
const cloudWatchLogs = new AWS.CloudWatchLogs({ region }); | ||
const logGroupName = getLogGroupName(functionName); | ||
const filterPattern = `"${pattern}"`; // enclose with "" to support special characters | ||
@@ -24,3 +24,3 @@ const { events = [] } = await cloudWatchLogs | ||
const cloudWatchLogs = new AWS.CloudWatchLogs({ region }); | ||
const logGroupName = getLogGroupName(functionName); | ||
const logGroupName = (0, exports.getLogGroupName)(functionName); | ||
const { logStreams = [] } = await cloudWatchLogs | ||
@@ -41,3 +41,3 @@ .describeLogStreams({ | ||
const cloudWatchLogs = new AWS.CloudWatchLogs({ region }); | ||
const logGroupName = getLogGroupName(functionName); | ||
const logGroupName = (0, exports.getLogGroupName)(functionName); | ||
const logStreamNames = logStreams.map((s) => s.logStreamName || ''); | ||
@@ -44,0 +44,0 @@ await Promise.all(logStreamNames.map((logStreamName) => { |
{ | ||
"name": "aws-testing-library", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Chai and Jest matchers for aws services", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
105068
1411