@Test public void testLambdaFunctionTags() throws HandlerException { BaseHandler.CONFIG_FILE = "/config/handler_config_tags.json"; TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:test_tags"); AWSLambdaClientFactory mockFactory = mock(AWSLambdaClientFactory.class); AWSLambda mockLambda = mock(AWSLambda.class); doReturn(mockLambda).when(mockFactory).newInstance(); ListTagsResult mockResult = mock(ListTagsResult.class); HashMap<String, String> expected = new HashMap<String, String>() { { put("t1", "foo"); put("t2", "bar"); } }; doReturn(expected).when(mockResult).getTags(); doReturn(mockResult).when(mockLambda).listTags(any()); handler.lambdaClientFactory = mockFactory; handler.init(context); Map<String, String> actual = handler.monitor.getTagsMap(); assertTrue(actual.entrySet().containsAll(expected.entrySet())); }
@Test public void tagsDuplicate() throws HandlerException { BaseHandler.CONFIG_FILE = "/config/handler_config_tags_duplicate.json"; TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:test_tags"); AWSLambdaClientFactory mockFactory = mock(AWSLambdaClientFactory.class); AWSLambda mockLambda = mock(AWSLambda.class); doReturn(mockLambda).when(mockFactory).newInstance(); ListTagsResult mockResult = mock(ListTagsResult.class); HashMap<String, String> functionTags = new HashMap<String, String>() { { put("f1", "foo"); put("f2", "foo"); } }; doReturn(functionTags).when(mockResult).getTags(); doReturn(mockResult).when(mockLambda).listTags(any()); handler.lambdaClientFactory = mockFactory; handler.init(context); Map<String, String> actual = handler.monitor.getTagsMap(); HashMap<String, String> expected = new HashMap<String, String>() { { put("f1", "foo"); put("f2", "foo"); put("u1", "bar"); } }; assertTrue(actual.entrySet().containsAll(expected.entrySet())); }
AWSLambda lambda = this.lambdaClientFactory.newInstance(); ListTagsResult res = lambda.listTags(new ListTagsRequest().withResource(ctx.getInvokedFunctionArn())); monitor.addTagsMap(res.getTags());
AWSLambda lambda = this.lambdaClientFactory.newInstance(); ListTagsResult res = lambda.listTags(new ListTagsRequest().withResource(ctx.getInvokedFunctionArn())); monitor.addTagsMap(res.getTags());