Search in sources :

Example 1 with ListVersionsByFunctionResult

use of com.amazonaws.services.lambda.model.ListVersionsByFunctionResult 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 ListVersionsByFunctionResult

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

the class LambdaVersionCleanupStepTest method ignoreLatest.

@Test
public void ignoreLatest() 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("$LATEST").withLastModified(ZonedDateTime.now().minusDays(15).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(functionName: 'foo', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ListVersionsByFunctionResult

use of com.amazonaws.services.lambda.model.ListVersionsByFunctionResult 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 4 with ListVersionsByFunctionResult

use of com.amazonaws.services.lambda.model.ListVersionsByFunctionResult 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)

Example 5 with ListVersionsByFunctionResult

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

the class LambdaVersionCleanupStepTest method ignoreAliases.

@Test
public void ignoreAliases() 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().withAliases(new AliasConfiguration().withFunctionVersion("myVersion")));
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("myVersion").withLastModified(ZonedDateTime.now().minusDays(15).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(functionName: 'foo', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    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) AliasConfiguration(com.amazonaws.services.lambda.model.AliasConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FunctionConfiguration (com.amazonaws.services.lambda.model.FunctionConfiguration)5 ListAliasesRequest (com.amazonaws.services.lambda.model.ListAliasesRequest)5 ListAliasesResult (com.amazonaws.services.lambda.model.ListAliasesResult)5 ListVersionsByFunctionRequest (com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest)5 ListVersionsByFunctionResult (com.amazonaws.services.lambda.model.ListVersionsByFunctionResult)5 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)5 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 DeleteFunctionRequest (com.amazonaws.services.lambda.model.DeleteFunctionRequest)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 AliasConfiguration (com.amazonaws.services.lambda.model.AliasConfiguration)1