Skip to content

Commit

Permalink
Introduce TestFunctionV2 to test integration in different payload ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
s4nchez committed Oct 5, 2020
1 parent 49bae27 commit d86d75b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object DeployApiGateway {

fun main() {
DeployApiGateway.deploy(ApiIntegrationVersion.v1)
DeployApiGateway.deploy(ApiIntegrationVersion.v2)
}

fun waitUntil(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ object DeployServerAsLambdaForClientContract {

fun functionName(version: ApiIntegrationVersion) = FunctionName("test-function-${version.name}")

private fun functionMainClass(version: ApiIntegrationVersion):String = when (version) {
private fun functionMainClass(version: ApiIntegrationVersion): String = when (version) {
v1 -> "org.http4k.serverless.lambda.TestFunctionV1"
v2 -> "org.http4k.serverless.lambda.TestFunctionV2"
}
}

fun main() {
DeployServerAsLambdaForClientContract.deploy(v1)
DeployServerAsLambdaForClientContract.deploy(v2)
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.http4k.serverless.lambda.client

import org.http4k.aws.ApiIntegrationVersion
import org.http4k.aws.ApiIntegrationVersion.v1
import org.http4k.client.HttpClientContract
import org.http4k.client.OkHttp
Expand All @@ -11,7 +12,7 @@ import org.junit.jupiter.api.Assumptions.assumeTrue
import org.opentest4j.TestAbortedException

private val apiClient by lazy {
val api = apiGatewayClient.listApis().find { it.name == apiName(v1) }
val api = apiGatewayClient.listApis().find { it.name == apiName(ApiIntegrationVersion.v2) }
?: throw TestAbortedException("API hasn't been deployed")
ClientFilters.SetBaseUriFrom(api.apiEndpoint).then(OkHttp())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.http4k.serverless.lambda.client

import org.http4k.aws.ApiIntegrationVersion
import org.http4k.aws.ApiIntegrationVersion.v1
import org.http4k.aws.AwsApiGatewayApiClient
import org.http4k.aws.AwsCredentialScope
import org.http4k.aws.AwsCredentials
Expand All @@ -15,10 +17,11 @@ import org.http4k.core.NoOp
import org.http4k.core.then
import org.http4k.filter.AwsAuth
import org.http4k.filter.ClientFilters
import org.http4k.serverless.lambda.DeployServerAsLambdaForClientContract
import org.junit.jupiter.api.Assumptions.assumeTrue

val testFunctionClient by lazy {
LambdaHttpClient(FunctionName("test-function"), Config.region(awsConfig)).then(awsClient("lambda"))
LambdaHttpClient(DeployServerAsLambdaForClientContract.functionName(v1), Config.region(awsConfig)).then(awsClient("lambda"))
}

val lambdaApiClient by lazy { AwsLambdaApiClient(awsClient("lambda"), Config.region(awsConfig)) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.http4k.serverless.lambda

import org.http4k.client.ServerForClientContract
import org.http4k.serverless.ApiGatewayV2LambdaFunction

class TestFunctionV2 : ApiGatewayV2LambdaFunction(ServerForClientContract)

0 comments on commit d86d75b

Please sign in to comment.