@@ -11,6 +11,38 @@ import * as treeNodeUtils from '../../shared/utilities/treeNodeUtils'
1111import * as resourceNode from '../../awsService/appBuilder/explorer/nodes/resourceNode'
1212import * as invokeLambdaModule from '../../lambda/vue/remoteInvoke/invokeLambda'
1313import * as tailLogGroupModule from '../../awsService/cloudWatchLogs/commands/tailLogGroup'
14+ import { LogDataRegistry } from '../../awsService/cloudWatchLogs/registry/logDataRegistry'
15+ import * as searchLogGroupModule from '../../awsService/cloudWatchLogs/commands/searchLogGroup'
16+
17+ const mockGeneratedLambdaNode : LambdaFunctionNode = {
18+ functionName : 'generatedFunction' ,
19+ regionCode : 'us-east-1' ,
20+ configuration : {
21+ FunctionName : 'generatedFunction' ,
22+ FunctionArn : 'arn:aws:lambda:us-east-1:123456789012:function:generatedFunction' ,
23+ } ,
24+ } as LambdaFunctionNode
25+
26+ const mockTreeNode = {
27+ resource : {
28+ deployedResource : { LogicalResourceId : 'TestFunction' } ,
29+ region : 'us-east-1' ,
30+ stackName : 'TestStack' ,
31+ resource : { Id : 'TestFunction' , Type : 'AWS::Serverless::Function' } ,
32+ } ,
33+ }
34+
35+ const mockLambdaNode : LambdaFunctionNode = {
36+ functionName : 'testFunction' ,
37+ regionCode : 'us-west-2' ,
38+ configuration : {
39+ FunctionName : 'testFunction' ,
40+ FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:testFunction' ,
41+ LoggingConfig : {
42+ LogGroup : '/aws/lambda/custom-log-group' ,
43+ } ,
44+ } ,
45+ } as LambdaFunctionNode
1446
1547describe ( 'Lambda activation' , ( ) => {
1648 let sandbox : sinon . SinonSandbox
@@ -19,9 +51,13 @@ describe('Lambda activation', () => {
1951 let invokeRemoteLambdaStub : sinon . SinonStub
2052 let tailLogGroupStub : sinon . SinonStub
2153 let isTreeNodeStub : sinon . SinonStub
54+ let searchLogGroupStub : sinon . SinonStub
55+ let registry : LogDataRegistry
2256
2357 beforeEach ( async ( ) => {
2458 sandbox = sinon . createSandbox ( )
59+ searchLogGroupStub = sandbox . stub ( searchLogGroupModule , 'searchLogGroup' )
60+ registry = LogDataRegistry . instance
2561 getSourceNodeStub = sandbox . stub ( treeNodeUtils , 'getSourceNode' )
2662 generateLambdaNodeFromResourceStub = sandbox . stub ( resourceNode , 'generateLambdaNodeFromResource' )
2763 invokeRemoteLambdaStub = sandbox . stub ( invokeLambdaModule , 'invokeRemoteLambda' )
@@ -32,18 +68,56 @@ describe('Lambda activation', () => {
3268 afterEach ( ( ) => {
3369 sandbox . restore ( )
3470 } )
71+ describe ( 'aws.appBuilder.searchLogs command' , ( ) => {
72+ it ( 'should handle LambdaFunctionNode directly' , async ( ) => {
73+ getSourceNodeStub . returns ( mockLambdaNode )
74+ isTreeNodeStub . returns ( false )
75+ searchLogGroupStub . resolves ( )
76+
77+ const node = { }
78+ await vscode . commands . executeCommand ( 'aws.appBuilder.searchLogs' , node )
79+
80+ assert ( searchLogGroupStub . calledOnce )
81+ assert (
82+ searchLogGroupStub . calledWith ( registry , 'AppBuilderSearchLogs' , {
83+ regionName : 'us-west-2' ,
84+ groupName : '/aws/lambda/custom-log-group' ,
85+ } )
86+ )
87+ } )
88+
89+ it ( 'should generate LambdaFunctionNode from TreeNode when getSourceNode returns undefined' , async ( ) => {
90+ getSourceNodeStub . returns ( undefined )
91+ isTreeNodeStub . returns ( true )
92+ generateLambdaNodeFromResourceStub . resolves ( mockGeneratedLambdaNode )
93+ searchLogGroupStub . resolves ( )
94+
95+ await vscode . commands . executeCommand ( 'aws.appBuilder.searchLogs' , mockTreeNode )
96+
97+ assert ( generateLambdaNodeFromResourceStub . calledOnce )
98+ assert ( generateLambdaNodeFromResourceStub . calledWith ( mockTreeNode . resource ) )
99+ assert ( searchLogGroupStub . calledOnce )
100+ assert (
101+ searchLogGroupStub . calledWith ( registry , 'AppBuilderSearchLogs' , {
102+ regionName : 'us-east-1' ,
103+ groupName : '/aws/lambda/generatedFunction' ,
104+ } )
105+ )
106+ } )
107+
108+ it ( 'should log error and throw ToolkitError when generateLambdaNodeFromResource fails' , async ( ) => {
109+ getSourceNodeStub . returns ( undefined )
110+ isTreeNodeStub . returns ( true )
111+ generateLambdaNodeFromResourceStub . rejects ( new Error ( 'Failed to generate node' ) )
112+ searchLogGroupStub . resolves ( )
113+
114+ await vscode . commands . executeCommand ( 'aws.appBuilder.searchLogs' , mockTreeNode )
115+ assert ( searchLogGroupStub . notCalled )
116+ } )
117+ } )
35118
36119 describe ( 'aws.invokeLambda command' , ( ) => {
37120 it ( 'should handle LambdaFunctionNode directly from AWS Explorer' , async ( ) => {
38- const mockLambdaNode : LambdaFunctionNode = {
39- functionName : 'testFunction' ,
40- regionCode : 'us-west-2' ,
41- configuration : {
42- FunctionName : 'testFunction' ,
43- FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:testFunction' ,
44- } ,
45- } as LambdaFunctionNode
46-
47121 isTreeNodeStub . returns ( false )
48122 invokeRemoteLambdaStub . resolves ( )
49123
@@ -56,24 +130,6 @@ describe('Lambda activation', () => {
56130 } )
57131
58132 it ( 'should generate LambdaFunctionNode from TreeNode when coming from AppBuilder' , async ( ) => {
59- const mockGeneratedLambdaNode : LambdaFunctionNode = {
60- functionName : 'generatedFunction' ,
61- regionCode : 'us-east-1' ,
62- configuration : {
63- FunctionName : 'generatedFunction' ,
64- FunctionArn : 'arn:aws:lambda:us-east-1:123456789012:function:generatedFunction' ,
65- } ,
66- } as LambdaFunctionNode
67-
68- const mockTreeNode = {
69- resource : {
70- deployedResource : { LogicalResourceId : 'TestFunction' } ,
71- region : 'us-east-1' ,
72- stackName : 'TestStack' ,
73- resource : { Id : 'TestFunction' , Type : 'AWS::Serverless::Function' } ,
74- } ,
75- }
76-
77133 isTreeNodeStub . returns ( true )
78134 getSourceNodeStub . returns ( undefined )
79135 generateLambdaNodeFromResourceStub . resolves ( mockGeneratedLambdaNode )
@@ -90,15 +146,6 @@ describe('Lambda activation', () => {
90146 } )
91147
92148 it ( 'should handle existing LambdaFunctionNode from TreeNode' , async ( ) => {
93- const mockLambdaNode : LambdaFunctionNode = {
94- functionName : 'existingFunction' ,
95- regionCode : 'us-west-2' ,
96- configuration : {
97- FunctionName : 'existingFunction' ,
98- FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:existingFunction' ,
99- } ,
100- } as LambdaFunctionNode
101-
102149 const mockTreeNode = {
103150 resource : { } ,
104151 }
@@ -119,17 +166,6 @@ describe('Lambda activation', () => {
119166
120167 describe ( 'aws.appBuilder.tailLogs command' , ( ) => {
121168 it ( 'should handle LambdaFunctionNode directly' , async ( ) => {
122- const mockLambdaNode : LambdaFunctionNode = {
123- functionName : 'testFunction' ,
124- regionCode : 'us-west-2' ,
125- configuration : {
126- FunctionName : 'testFunction' ,
127- LoggingConfig : {
128- LogGroup : '/aws/lambda/custom-log-group' ,
129- } ,
130- } ,
131- } as LambdaFunctionNode
132-
133169 isTreeNodeStub . returns ( false )
134170 getSourceNodeStub . returns ( mockLambdaNode )
135171 tailLogGroupStub . resolves ( )
@@ -155,15 +191,6 @@ describe('Lambda activation', () => {
155191 } ,
156192 } as LambdaFunctionNode
157193
158- const mockTreeNode = {
159- resource : {
160- deployedResource : { LogicalResourceId : 'TestFunction' } ,
161- region : 'us-east-1' ,
162- stackName : 'TestStack' ,
163- resource : { Id : 'TestFunction' , Type : 'AWS::Serverless::Function' } ,
164- } ,
165- }
166-
167194 isTreeNodeStub . returns ( true )
168195 getSourceNodeStub . returns ( undefined )
169196 generateLambdaNodeFromResourceStub . resolves ( mockGeneratedLambdaNode )
0 commit comments