chore(test/lambda): Add tests for lambda operations
MODIFY
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/UpdateLambdaConfigurationAtomicOperation.java
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/UpdateLambdaConfigurationAtomicOperation.java
@@ -105,7 +105,7 @@ public class UpdateLambdaConfigurationAtomicOperation
}
updateTaskStatus("Finished Updating of AWS Lambda Function Configuration Operation...");
if (StringUtils.isEmpty(description.getTargetGroups())) {
- if (!cache.getTargetGroups().isEmpty()) {
+ if (cache.getTargetGroups() != null && !cache.getTargetGroups().isEmpty()) {
AmazonElasticLoadBalancing loadBalancingV2 = getAmazonElasticLoadBalancingClient();
for (String groupName : cache.getTargetGroups()) {
deregisterTarget(

DELETE
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/InvokeLambdaAtomicOperationTest.java
-/*
- * Copyright 2018 Amazon.com, Inc. or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.netflix.spinnaker.clouddriver.lambda;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.util.function.IntPredicate;
-import org.junit.jupiter.api.Test;
-import org.junit.platform.runner.JUnitPlatform;
-import org.junit.runner.RunWith;
-
-@RunWith(JUnitPlatform.class)
-public class InvokeLambdaAtomicOperationTest {
-
- @Test
- void dummyTest() throws IOException {
- assertThat(
- (IntPredicate)
- x -> {
- return true;
- });
- }
-}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/CreateLambdaAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.CreateFunctionRequest;
+import com.amazonaws.services.lambda.model.CreateFunctionResult;
+import com.amazonaws.services.lambda.model.DeadLetterConfig;
+import com.amazonaws.services.lambda.model.FunctionCode;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.CreateLambdaFunctionDescription;
+import org.junit.jupiter.api.Test;
+
+public class CreateLambdaAtomicOperationTest {
+ @Test
+ void testPublishLambda() {
+ // given
+ CreateLambdaFunctionDescription b =
+ new CreateLambdaFunctionDescription()
+ .setS3bucket("s3://bucket")
+ .setS3key("key/key/path")
+ .setAppName("appName")
+ .setFunctionName("funcName")
+ .setDeadLetterConfig(new DeadLetterConfig().withTargetArn(""));
+ CreateLambdaAtomicOperation clao = spy(new CreateLambdaAtomicOperation(b));
+ doNothing().when(clao).updateTaskStatus(anyString());
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ doReturn(lambdaClient).when(clao).getLambdaClient();
+ CreateFunctionRequest createRequest =
+ new CreateFunctionRequest()
+ .withFunctionName("appName-funcName")
+ .withCode(new FunctionCode().withS3Bucket("s3://bucket").withS3Key("key/key/path"));
+ CreateFunctionResult createLambdaResult =
+ new CreateFunctionResult()
+ .withFunctionName("appName-funcName")
+ .withCodeSha256("abc123def456");
+ doReturn(createLambdaResult).when(lambdaClient).createFunction(createRequest);
+ // when
+ CreateFunctionResult output = clao.operate(null);
+ // then
+ verify(clao, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(createLambdaResult);
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/DeleteLambdaAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.DeleteFunctionRequest;
+import com.amazonaws.services.lambda.model.DeleteFunctionResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.DeleteLambdaFunctionDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class DeleteLambdaAtomicOperationTest implements LambdaTestingDefaults {
+ @Test
+ void testDeleteLambda() {
+ DeleteLambdaFunctionDescription deleteDesc = new DeleteLambdaFunctionDescription();
+ deleteDesc.setFunctionName(fName).setQualifier(version).setRegion(region).setAccount(account);
+
+ DeleteLambdaAtomicOperation deleteOperation = spy(new DeleteLambdaAtomicOperation(deleteDesc));
+ doNothing().when(deleteOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+ ReflectionTestUtils.setField(deleteOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ doReturn(lambdaClient).when(deleteOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ DeleteFunctionRequest deleteRequest = new DeleteFunctionRequest();
+ deleteRequest.withQualifier(version).withFunctionName(functionArn);
+ DeleteFunctionResult mockDeleteResult = new DeleteFunctionResult();
+ doReturn(mockDeleteResult).when(lambdaClient).deleteFunction(deleteRequest);
+
+ DeleteFunctionResult output = deleteOperation.operate(null);
+ verify(deleteOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockDeleteResult);
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/DeleteLambdaEventSourceAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingRequest;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.UpsertLambdaFunctionEventMappingDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class DeleteLambdaEventSourceAtomicOperationTest implements LambdaTestingDefaults {
+ @Test
+ void testUpdateLambdaEventMapping() {
+ UpsertLambdaFunctionEventMappingDescription eventMappingDesc =
+ new UpsertLambdaFunctionEventMappingDescription();
+ eventMappingDesc
+ .setFunctionName(fName)
+ .setBatchsize(1)
+ .setEnabled(true)
+ .setEventSourceArn(eventArn)
+ .setUuid(eventUuid)
+ .setRegion(region)
+ .setAccount(account);
+ ;
+ DeleteLambdaEventSourceAtomicOperation deleteEventSourceOperation =
+ spy(new DeleteLambdaEventSourceAtomicOperation(eventMappingDesc));
+ doNothing().when(deleteEventSourceOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+
+ ReflectionTestUtils.setField(
+ deleteEventSourceOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+ doReturn(lambdaClient).when(deleteEventSourceOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ DeleteEventSourceMappingRequest testRequest = new DeleteEventSourceMappingRequest();
+ testRequest.setUUID(eventUuid);
+
+ DeleteEventSourceMappingResult mockDeleteEventResult = new DeleteEventSourceMappingResult();
+ doReturn(mockDeleteEventResult).when(lambdaClient).deleteEventSourceMapping(testRequest);
+
+ Object output = deleteEventSourceOperation.operate(null);
+ verify(deleteEventSourceOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockDeleteEventResult);
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/InvokeLambdaAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.InvokeRequest;
+import com.amazonaws.services.lambda.model.InvokeResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.InvokeLambdaFunctionDescription;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.InvokeLambdaFunctionOutputDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class InvokeLambdaAtomicOperationTest implements LambdaTestingDefaults {
+ @Test
+ void testInvokeLambda() {
+ InvokeLambdaFunctionDescription invokeDesc = new InvokeLambdaFunctionDescription();
+ invokeDesc.setFunctionName(fName).setQualifier(version).setRegion(region).setAccount(account);
+
+ InvokeLambdaAtomicOperation invokeOperation = spy(new InvokeLambdaAtomicOperation(invokeDesc));
+ doNothing().when(invokeOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+ ReflectionTestUtils.setField(invokeOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ doReturn(lambdaClient).when(invokeOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ InvokeRequest invokeRequest = new InvokeRequest();
+ invokeRequest.withQualifier(version).withFunctionName(functionArn);
+ InvokeResult mockDeleteResult = new InvokeResult();
+ doReturn(mockDeleteResult).when(lambdaClient).invoke(invokeRequest);
+
+ InvokeLambdaFunctionOutputDescription output = invokeOperation.operate(null);
+ verify(invokeOperation, atLeastOnce()).updateTaskStatus(anyString());
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/LambdaTestingDefaults.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import com.amazonaws.services.lambda.model.AliasConfiguration;
+import com.amazonaws.services.lambda.model.EventSourceMappingConfiguration;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import java.util.ArrayList;
+import java.util.List;
+
+public interface LambdaTestingDefaults {
+
+ String fName = "app1-stack1-detail1-function1";
+ String functionArn = "function1:arn";
+ String region = "us-west-2";
+ String account = "account-1";
+ String version = "1";
+ String eventArn = "arn-1";
+ String eventUuid = "uuid-1";
+ String revisionId = "1";
+ String revisionDesc = "Revision Desc";
+ String aliasName = "fAlias";
+ String aliasArn = "alias-arn-1";
+ String aliasDesc = "Alias Description";
+
+ default LambdaFunction getMockedFunctionDefintion() {
+ LambdaFunction cachedFunction = new LambdaFunction();
+ cachedFunction.setFunctionName(fName);
+ cachedFunction.setFunctionArn(functionArn);
+ cachedFunction.setRegion(region);
+ cachedFunction.setAccount(account);
+ cachedFunction.setAliasConfigurations(getMockAliases());
+ cachedFunction.setEventSourceMappings(getMockEventSourceList());
+ return cachedFunction;
+ }
+
+ default List<AliasConfiguration> getMockAliases() {
+ AliasConfiguration es = new AliasConfiguration();
+ es.setAliasArn(aliasArn);
+ es.setDescription(aliasDesc);
+ es.setName(aliasName);
+ es.setRevisionId(revisionId);
+ List<AliasConfiguration> le = new ArrayList();
+ le.add(es);
+ return le;
+ }
+
+ default List<EventSourceMappingConfiguration> getMockEventSourceList() {
+ EventSourceMappingConfiguration es = new EventSourceMappingConfiguration();
+ es.setUUID(eventUuid);
+ es.setEventSourceArn(eventArn);
+ List<EventSourceMappingConfiguration> le = new ArrayList();
+ le.add(es);
+ return le;
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/PublishLambdaAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.PublishVersionRequest;
+import com.amazonaws.services.lambda.model.PublishVersionResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PublishLambdaFunctionVersionDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class PublishLambdaAtomicOperationTest implements LambdaTestingDefaults {
+
+ @Test
+ void testPublishLambda() {
+ PublishLambdaFunctionVersionDescription publishDesc =
+ new PublishLambdaFunctionVersionDescription();
+ publishDesc
+ .setFunctionName(fName)
+ .setDescription(revisionDesc)
+ .setRevisionId(revisionId)
+ .setRegion(region)
+ .setAccount(account);
+ ;
+
+ PublishLambdaAtomicOperation publishOperation =
+ spy(new PublishLambdaAtomicOperation(publishDesc));
+ doNothing().when(publishOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+
+ ReflectionTestUtils.setField(
+ publishOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+ doReturn(lambdaClient).when(publishOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ PublishVersionRequest testRequest = new PublishVersionRequest();
+ testRequest.setFunctionName(fName);
+ testRequest.setRevisionId(revisionId);
+ testRequest.setDescription(revisionDesc);
+
+ PublishVersionResult mockPublishResult = new PublishVersionResult();
+ doReturn(mockPublishResult).when(lambdaClient).publishVersion(testRequest);
+
+ PublishVersionResult output = publishOperation.operate(null);
+ verify(publishOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockPublishResult);
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/PutConcurrencyAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.PutFunctionConcurrencyRequest;
+import com.amazonaws.services.lambda.model.PutFunctionConcurrencyResult;
+import com.amazonaws.services.lambda.model.PutProvisionedConcurrencyConfigRequest;
+import com.amazonaws.services.lambda.model.PutProvisionedConcurrencyConfigResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaProvisionedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaReservedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class PutConcurrencyAtomicOperationTest implements LambdaTestingDefaults {
+
+ @Test
+ void testProvisionedConcurrency() {
+ PutLambdaProvisionedConcurrencyDescription provisionedConcurrencyDescription =
+ new PutLambdaProvisionedConcurrencyDescription();
+ provisionedConcurrencyDescription
+ .setFunctionName(fName)
+ .setQualifier(version)
+ .setProvisionedConcurrentExecutions(2)
+ .setRegion(region)
+ .setAccount(account);
+ ;
+
+ PutLambdaProvisionedConcurrencyAtomicOperation putConcurrencyOperation =
+ spy(new PutLambdaProvisionedConcurrencyAtomicOperation(provisionedConcurrencyDescription));
+ doNothing().when(putConcurrencyOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+
+ ReflectionTestUtils.setField(
+ putConcurrencyOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+ doReturn(lambdaClient).when(putConcurrencyOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ PutProvisionedConcurrencyConfigRequest testRequest =
+ new PutProvisionedConcurrencyConfigRequest();
+ testRequest.setFunctionName(fName);
+ testRequest.setQualifier(version);
+ testRequest.setProvisionedConcurrentExecutions(2);
+
+ PutProvisionedConcurrencyConfigResult mockProvisionResult =
+ new PutProvisionedConcurrencyConfigResult();
+ mockProvisionResult.setAllocatedProvisionedConcurrentExecutions(2);
+ mockProvisionResult.setAvailableProvisionedConcurrentExecutions(4);
+ mockProvisionResult.setStatus("provisioned");
+ doReturn(mockProvisionResult).when(lambdaClient).putProvisionedConcurrencyConfig(testRequest);
+
+ PutProvisionedConcurrencyConfigResult output = putConcurrencyOperation.operate(null);
+ verify(putConcurrencyOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockProvisionResult);
+ }
+
+ @Test
+ void testReservedConcurrency() {
+ PutLambdaReservedConcurrencyDescription provisionedConcurrencyDescription =
+ new PutLambdaReservedConcurrencyDescription();
+ provisionedConcurrencyDescription
+ .setFunctionName(fName)
+ .setReservedConcurrentExecutions(2)
+ .setRegion(region)
+ .setAccount(account);
+ ;
+
+ PutLambdaReservedConcurrencyAtomicOperation putConcurrencyOperation =
+ spy(new PutLambdaReservedConcurrencyAtomicOperation(provisionedConcurrencyDescription));
+ doNothing().when(putConcurrencyOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+
+ ReflectionTestUtils.setField(
+ putConcurrencyOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+ doReturn(lambdaClient).when(putConcurrencyOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ PutFunctionConcurrencyRequest testRequest = new PutFunctionConcurrencyRequest();
+ testRequest.setReservedConcurrentExecutions(2);
+ testRequest.setFunctionName(fName);
+
+ PutFunctionConcurrencyResult mockProvisionResult = new PutFunctionConcurrencyResult();
+ doReturn(mockProvisionResult).when(lambdaClient).putFunctionConcurrency(testRequest);
+
+ PutFunctionConcurrencyResult output = putConcurrencyOperation.operate(null);
+ verify(putConcurrencyOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockProvisionResult);
+ }
+}

ADD
clouddriver-lambda/src/test/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/UpdateLambdaAtomicOperationTest.java
+/*
+ * Copyright 2020 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.lambda.deploy.ops;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.UpdateFunctionCodeRequest;
+import com.amazonaws.services.lambda.model.UpdateFunctionCodeResult;
+import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.UpdateLambdaFunctionCodeDescription;
+import com.netflix.spinnaker.clouddriver.lambda.provider.view.LambdaFunctionProvider;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class UpdateLambdaAtomicOperationTest implements LambdaTestingDefaults {
+
+ @Test
+ void testUpdateLambdaCode() {
+ UpdateLambdaFunctionCodeDescription updateCodeDesc = new UpdateLambdaFunctionCodeDescription();
+ updateCodeDesc.setFunctionName(fName).setRegion(region).setAccount(account);
+
+ UpdateLambdaCodeAtomicOperation updateCodeOperation =
+ spy(new UpdateLambdaCodeAtomicOperation(updateCodeDesc));
+ doNothing().when(updateCodeOperation).updateTaskStatus(anyString());
+
+ AWSLambda lambdaClient = mock(AWSLambda.class);
+ LambdaFunction cachedFunction = getMockedFunctionDefintion();
+
+ LambdaFunctionProvider lambdaFunctionProvider = mock(LambdaFunctionProvider.class);
+ ReflectionTestUtils.setField(
+ updateCodeOperation, "lambdaFunctionProvider", lambdaFunctionProvider);
+
+ doReturn(lambdaClient).when(updateCodeOperation).getLambdaClient();
+ doReturn(cachedFunction)
+ .when(lambdaFunctionProvider)
+ .getFunction(anyString(), anyString(), anyString());
+
+ UpdateFunctionCodeRequest updateCodeRequest = new UpdateFunctionCodeRequest();
+ updateCodeRequest.withFunctionName(functionArn);
+ UpdateFunctionCodeResult mockCodeResult = new UpdateFunctionCodeResult();
+ doReturn(mockCodeResult).when(lambdaClient).updateFunctionCode(updateCodeRequest);
+
+ UpdateFunctionCodeResult output = updateCodeOperation.operate(null);
+ verify(updateCodeOperation, atLeastOnce()).updateTaskStatus(anyString());
+ assertThat(output).isEqualTo(mockCodeResult);
+ }
+
+ @Test
+ void testUpdateLambdaConfig() {
+ // TODO
+ }
+}

chore(test/lambda): Add tests for lambda operations (#5084)