forked from XT-i/aws-lambda-jenkins-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added env var expanding to payload and json parameters
- Loading branch information
Showing
8 changed files
with
307 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,6 +245,7 @@ public String getDisplayName() { | |
return "Deploy into Lambda"; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/com/xti/jenkins/plugin/awslambda/LambdaVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.xti.jenkins.plugin.awslambda; | ||
|
||
import com.amazonaws.services.lambda.AWSLambda; | ||
import com.xti.jenkins.plugin.awslambda.upload.DeployConfig; | ||
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; | ||
import hudson.EnvVars; | ||
import hudson.util.Secret; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LambdaVariablesTest { | ||
|
||
@Test | ||
public void testCloneExpandVariables() throws Exception { | ||
LambdaVariables variables = new LambdaVariables("${ENV_ID}", Secret.fromString("$ENV_SECRET}"), "${ENV_REGION}", "${ENV_FILE}", "description ${ENV_DESCRIPTION}", "${ENV_FUNCTION}", "${ENV_HANDLER}", 1024, "${ENV_ROLE}", "$ENV_RUNTIME", 30, true, "full"); | ||
LambdaVariables clone = variables.getClone(); | ||
|
||
EnvVars envVars = new EnvVars(); | ||
envVars.put("ENV_ID", "ID"); | ||
envVars.put("ENV_SECRET", "SECRET"); | ||
envVars.put("ENV_REGION", "eu-west-1"); | ||
envVars.put("ENV_FILE", "FILE"); | ||
envVars.put("ENV_DESCRIPTION", "DESCRIPTION"); | ||
envVars.put("ENV_FUNCTION", "FUNCTION"); | ||
envVars.put("ENV_HANDLER", "HANDLER"); | ||
envVars.put("ENV_ROLE", "ROLE"); | ||
envVars.put("ENV_RUNTIME", "RUNTIME"); | ||
clone.expandVariables(envVars); | ||
|
||
LambdaVariables expected = new LambdaVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, true, "full"); | ||
|
||
assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); | ||
assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); | ||
assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); | ||
assertEquals(expected.getArtifactLocation(), clone.getArtifactLocation()); | ||
assertEquals(expected.getDescription(), clone.getDescription()); | ||
assertEquals(expected.getFunctionName(), clone.getFunctionName()); | ||
assertEquals(expected.getMemorySize(), clone.getMemorySize()); | ||
assertEquals(expected.getTimeout(), clone.getTimeout()); | ||
assertEquals(expected.getHandler(), clone.getHandler()); | ||
assertEquals(expected.getRole(), clone.getRole()); | ||
assertEquals(expected.getRuntime(), clone.getRuntime()); | ||
assertEquals(expected.getSuccessOnly(), clone.getSuccessOnly()); | ||
} | ||
|
||
@Test | ||
public void testGetUploadConfig() throws Exception { | ||
LambdaVariables variables = new LambdaVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, true, "full"); | ||
DeployConfig uploadConfig = variables.getUploadConfig(); | ||
|
||
assertEquals(variables.getArtifactLocation(), uploadConfig.getArtifactLocation()); | ||
assertEquals(variables.getDescription(), uploadConfig.getDescription()); | ||
assertEquals(variables.getMemorySize(), uploadConfig.getMemorySize()); | ||
assertEquals(variables.getTimeout(), uploadConfig.getTimeout()); | ||
assertEquals(variables.getHandler(), uploadConfig.getHandler()); | ||
assertEquals(variables.getRuntime(), uploadConfig.getRuntime()); | ||
assertEquals(variables.getFunctionName(), uploadConfig.getFunctionName()); | ||
assertEquals(variables.getRole(), uploadConfig.getRole()); | ||
assertEquals(variables.getUpdateMode(), uploadConfig.getUpdateMode()); | ||
} | ||
|
||
@Test | ||
public void testGetLambdaClientConfig() throws Exception { | ||
LambdaVariables variables = new LambdaVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, true, "full"); | ||
LambdaClientConfig lambdaClientConfig = variables.getLambdaClientConfig(); | ||
|
||
AWSLambda lambda = lambdaClientConfig.getClient(); | ||
assertNotNull(lambda); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeBuildStepVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.xti.jenkins.plugin.awslambda.invoke; | ||
|
||
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; | ||
import hudson.EnvVars; | ||
import hudson.util.Secret; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LambdaInvokeBuildStepVariablesTest { | ||
|
||
@Test | ||
public void testCloneExpandVariables() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_$ENV_ENV_NAME", "$.$ENV_JSON_PATH")); | ||
LambdaInvokeBuildStepVariables variables = new LambdaInvokeBuildStepVariables("${ENV_ID}", Secret.fromString("$ENV_SECRET}"), "${ENV_REGION}", "${ENV_FUNCTION}", "${\"payload\":\"${ENV_PAYLOAD}\"", true, jsonParameterVariables); | ||
LambdaInvokeBuildStepVariables clone = variables.getClone(); | ||
|
||
EnvVars envVars = new EnvVars(); | ||
envVars.put("ENV_ID", "ID"); | ||
envVars.put("ENV_SECRET", "SECRET"); | ||
envVars.put("ENV_REGION", "eu-west-1"); | ||
envVars.put("ENV_FUNCTION", "FUNCTION"); | ||
envVars.put("ENV_PAYLOAD", "hello"); | ||
envVars.put("ENV_ENV_NAME", "NAME"); | ||
envVars.put("ENV_JSON_PATH", "path"); | ||
envVars.put(".", "bad"); | ||
clone.expandVariables(envVars); | ||
|
||
List<JsonParameterVariables> jsonParameterVariablesExpected = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariablesExpected.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeBuildStepVariables expected = new LambdaInvokeBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, jsonParameterVariablesExpected); | ||
|
||
assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); | ||
assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); | ||
assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); | ||
assertEquals(expected.getFunctionName(), clone.getFunctionName()); | ||
assertEquals(expected.getPayload(), clone.getPayload()); | ||
assertEquals(expected.getSynchronous(), clone.getSynchronous()); | ||
assertEquals(expected.getJsonParameters().get(0).getEnvVarName(), clone.getJsonParameters().get(0).getEnvVarName()); | ||
assertEquals(expected.getJsonParameters().get(0).getJsonPath(), clone.getJsonParameters().get(0).getJsonPath()); | ||
} | ||
|
||
@Test | ||
public void testGetInvokeConfig() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeBuildStepVariables variables = new LambdaInvokeBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, jsonParameterVariables); | ||
InvokeConfig invokeConfig = variables.getInvokeConfig(); | ||
|
||
assertEquals(variables.getFunctionName(), invokeConfig.getFunctionName()); | ||
assertEquals(variables.getPayload(), invokeConfig.getPayload()); | ||
assertEquals(variables.getSynchronous(), invokeConfig.isSynchronous()); | ||
assertEquals(variables.getJsonParameters().get(0).getEnvVarName(), invokeConfig.getJsonParameters().get(0).getEnvVarName()); | ||
assertEquals(variables.getJsonParameters().get(0).getJsonPath(), invokeConfig.getJsonParameters().get(0).getJsonPath()); | ||
} | ||
|
||
@Test | ||
public void testGetLambdaClientConfig() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeBuildStepVariables variables = new LambdaInvokeBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, jsonParameterVariables); | ||
|
||
LambdaClientConfig clientConfig = variables.getLambdaClientConfig(); | ||
assertNotNull(clientConfig); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokeVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.xti.jenkins.plugin.awslambda.invoke; | ||
|
||
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; | ||
import hudson.EnvVars; | ||
import hudson.util.Secret; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LambdaInvokeVariablesTest { | ||
|
||
@Test | ||
public void testCloneExpandVariables() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_$ENV_ENV_NAME", "$.$ENV_JSON_PATH")); | ||
LambdaInvokeVariables variables = new LambdaInvokeVariables("${ENV_ID}", Secret.fromString("$ENV_SECRET}"), "${ENV_REGION}", "${ENV_FUNCTION}", "${\"payload\":\"${ENV_PAYLOAD}\"", true, true, jsonParameterVariables); | ||
LambdaInvokeVariables clone = variables.getClone(); | ||
|
||
EnvVars envVars = new EnvVars(); | ||
envVars.put("ENV_ID", "ID"); | ||
envVars.put("ENV_SECRET", "SECRET"); | ||
envVars.put("ENV_REGION", "eu-west-1"); | ||
envVars.put("ENV_FUNCTION", "FUNCTION"); | ||
envVars.put("ENV_PAYLOAD", "hello"); | ||
envVars.put("ENV_ENV_NAME", "NAME"); | ||
envVars.put("ENV_JSON_PATH", "path"); | ||
envVars.put(".", "bad"); | ||
clone.expandVariables(envVars); | ||
|
||
List<JsonParameterVariables> jsonParameterVariablesExpected = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariablesExpected.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeVariables expected = new LambdaInvokeVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariablesExpected); | ||
|
||
assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); | ||
assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); | ||
assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); | ||
assertEquals(expected.getFunctionName(), clone.getFunctionName()); | ||
assertEquals(expected.getPayload(), clone.getPayload()); | ||
assertEquals(expected.getSynchronous(), clone.getSynchronous()); | ||
assertEquals(expected.getSuccessOnly(), clone.getSuccessOnly()); | ||
assertEquals(expected.getJsonParameters().get(0).getEnvVarName(), clone.getJsonParameters().get(0).getEnvVarName()); | ||
assertEquals(expected.getJsonParameters().get(0).getJsonPath(), clone.getJsonParameters().get(0).getJsonPath()); | ||
} | ||
|
||
@Test | ||
public void testGetInvokeConfig() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeVariables variables = new LambdaInvokeVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariables); | ||
InvokeConfig invokeConfig = variables.getInvokeConfig(); | ||
|
||
assertEquals(variables.getFunctionName(), invokeConfig.getFunctionName()); | ||
assertEquals(variables.getPayload(), invokeConfig.getPayload()); | ||
assertEquals(variables.getSynchronous(), invokeConfig.isSynchronous()); | ||
assertEquals(variables.getJsonParameters().get(0).getEnvVarName(), invokeConfig.getJsonParameters().get(0).getEnvVarName()); | ||
assertEquals(variables.getJsonParameters().get(0).getJsonPath(), invokeConfig.getJsonParameters().get(0).getJsonPath()); | ||
} | ||
|
||
@Test | ||
public void testGetLambdaClientConfig() throws Exception { | ||
List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>(); | ||
jsonParameterVariables.add(new JsonParameterVariables("ENV_NAME", "$.path")); | ||
LambdaInvokeVariables variables = new LambdaInvokeVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FUNCTION", "${\"payload\":\"hello\"", true, true, jsonParameterVariables); | ||
|
||
LambdaClientConfig clientConfig = variables.getLambdaClientConfig(); | ||
assertNotNull(clientConfig); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...test/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploadBuildStepVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.xti.jenkins.plugin.awslambda.upload; | ||
|
||
import com.amazonaws.services.lambda.AWSLambda; | ||
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig; | ||
import hudson.EnvVars; | ||
import hudson.util.Secret; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LambdaUploadBuildStepVariablesTest { | ||
|
||
@Test | ||
public void testCloneExpandVariables() throws Exception { | ||
LambdaUploadBuildStepVariables variables = new LambdaUploadBuildStepVariables("${ENV_ID}", Secret.fromString("$ENV_SECRET}"), "${ENV_REGION}", "${ENV_FILE}", "description ${ENV_DESCRIPTION}", "${ENV_FUNCTION}", "${ENV_HANDLER}", 1024, "${ENV_ROLE}", "$ENV_RUNTIME", 30, "full"); | ||
LambdaUploadBuildStepVariables clone = variables.getClone(); | ||
|
||
EnvVars envVars = new EnvVars(); | ||
envVars.put("ENV_ID", "ID"); | ||
envVars.put("ENV_SECRET", "SECRET"); | ||
envVars.put("ENV_REGION", "eu-west-1"); | ||
envVars.put("ENV_FILE", "FILE"); | ||
envVars.put("ENV_DESCRIPTION", "DESCRIPTION"); | ||
envVars.put("ENV_FUNCTION", "FUNCTION"); | ||
envVars.put("ENV_HANDLER", "HANDLER"); | ||
envVars.put("ENV_ROLE", "ROLE"); | ||
envVars.put("ENV_RUNTIME", "RUNTIME"); | ||
clone.expandVariables(envVars); | ||
|
||
LambdaUploadBuildStepVariables expected = new LambdaUploadBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, "full"); | ||
|
||
assertEquals(expected.getAwsAccessKeyId(), clone.getAwsAccessKeyId()); | ||
assertEquals(expected.getAwsSecretKey(), clone.getAwsSecretKey()); | ||
assertEquals(expected.getAwsRegion(), clone.getAwsRegion()); | ||
assertEquals(expected.getArtifactLocation(), clone.getArtifactLocation()); | ||
assertEquals(expected.getDescription(), clone.getDescription()); | ||
assertEquals(expected.getFunctionName(), clone.getFunctionName()); | ||
assertEquals(expected.getMemorySize(), clone.getMemorySize()); | ||
assertEquals(expected.getTimeout(), clone.getTimeout()); | ||
assertEquals(expected.getHandler(), clone.getHandler()); | ||
assertEquals(expected.getRole(), clone.getRole()); | ||
assertEquals(expected.getRuntime(), clone.getRuntime()); | ||
} | ||
|
||
@Test | ||
public void testGetUploadConfig() throws Exception { | ||
LambdaUploadBuildStepVariables variables = new LambdaUploadBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, "full"); | ||
DeployConfig uploadConfig = variables.getUploadConfig(); | ||
|
||
assertEquals(variables.getArtifactLocation(), uploadConfig.getArtifactLocation()); | ||
assertEquals(variables.getDescription(), uploadConfig.getDescription()); | ||
assertEquals(variables.getMemorySize(), uploadConfig.getMemorySize()); | ||
assertEquals(variables.getTimeout(), uploadConfig.getTimeout()); | ||
assertEquals(variables.getHandler(), uploadConfig.getHandler()); | ||
assertEquals(variables.getRuntime(), uploadConfig.getRuntime()); | ||
assertEquals(variables.getFunctionName(), uploadConfig.getFunctionName()); | ||
assertEquals(variables.getRole(), uploadConfig.getRole()); | ||
assertEquals(variables.getUpdateMode(), uploadConfig.getUpdateMode()); | ||
} | ||
|
||
@Test | ||
public void testGetLambdaClientConfig() throws Exception { | ||
LambdaUploadBuildStepVariables variables = new LambdaUploadBuildStepVariables("ID", Secret.fromString("SECRET}"), "eu-west-1", "FILE", "description DESCRIPTION", "FUNCTION", "HANDLER", 1024, "ROLE", "RUNTIME", 30, "full"); | ||
LambdaClientConfig lambdaClientConfig = variables.getLambdaClientConfig(); | ||
|
||
AWSLambda lambda = lambdaClientConfig.getClient(); | ||
assertNotNull(lambda); | ||
} | ||
} |