Search in sources :

Example 1 with DeleteFunctionRequest

use of com.amazonaws.services.lambda.model.DeleteFunctionRequest in project pipeline-aws-plugin by jenkinsci.

the class LambdaVersionCleanupStepTest method paginatedResponse.

@Test
public void paginatedResponse() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withNextMarker("baz"));
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo").withMarker("baz")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(functionName: 'foo', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo"));
    Mockito.verify(this.awsLambda, Mockito.times(2)).listVersionsByFunction(Mockito.any());
    Mockito.verify(this.awsLambda).listAliases(Mockito.any());
    Mockito.verifyNoMoreInteractions(this.awsLambda);
}
Also used : ListAliasesResult(com.amazonaws.services.lambda.model.ListAliasesResult) ListVersionsByFunctionResult(com.amazonaws.services.lambda.model.ListVersionsByFunctionResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FunctionConfiguration(com.amazonaws.services.lambda.model.FunctionConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DeleteFunctionRequest(com.amazonaws.services.lambda.model.DeleteFunctionRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with DeleteFunctionRequest

use of com.amazonaws.services.lambda.model.DeleteFunctionRequest in project pipeline-aws-plugin by jenkinsci.

the class LambdaVersionCleanupStepTest method deleteCloudFormationStack.

@Test
public void deleteCloudFormationStack() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo2")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo2")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")).withNextToken("foo"));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz").withNextToken("foo"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo2"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(stackName: 'baz', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo"));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo2"));
    Mockito.verify(this.awsLambda, Mockito.times(2)).listVersionsByFunction(Mockito.any());
    Mockito.verify(this.awsLambda, Mockito.times(2)).listAliases(Mockito.any());
    Mockito.verifyNoMoreInteractions(this.awsLambda);
}
Also used : ListAliasesResult(com.amazonaws.services.lambda.model.ListAliasesResult) ListVersionsByFunctionResult(com.amazonaws.services.lambda.model.ListVersionsByFunctionResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) FunctionConfiguration(com.amazonaws.services.lambda.model.FunctionConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DeleteFunctionRequest(com.amazonaws.services.lambda.model.DeleteFunctionRequest) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with DeleteFunctionRequest

use of com.amazonaws.services.lambda.model.DeleteFunctionRequest in project pipeline-aws-plugin by jenkinsci.

the class LambdaVersionCleanupStepTest method deleteSingleFunction.

@Test
public void deleteSingleFunction() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(functionName: 'foo', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo"));
    Mockito.verify(this.awsLambda).listVersionsByFunction(Mockito.any());
    Mockito.verify(this.awsLambda).listAliases(Mockito.any());
    Mockito.verifyNoMoreInteractions(this.awsLambda);
}
Also used : ListAliasesResult(com.amazonaws.services.lambda.model.ListAliasesResult) ListVersionsByFunctionResult(com.amazonaws.services.lambda.model.ListVersionsByFunctionResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FunctionConfiguration(com.amazonaws.services.lambda.model.FunctionConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DeleteFunctionRequest(com.amazonaws.services.lambda.model.DeleteFunctionRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DeleteFunctionRequest (com.amazonaws.services.lambda.model.DeleteFunctionRequest)3 FunctionConfiguration (com.amazonaws.services.lambda.model.FunctionConfiguration)3 ListAliasesRequest (com.amazonaws.services.lambda.model.ListAliasesRequest)3 ListAliasesResult (com.amazonaws.services.lambda.model.ListAliasesResult)3 ListVersionsByFunctionRequest (com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest)3 ListVersionsByFunctionResult (com.amazonaws.services.lambda.model.ListVersionsByFunctionResult)3 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)1 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)1 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)1