-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleLambda3.test.scala
77 lines (58 loc) · 2.21 KB
/
ExampleLambda3.test.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.encalmo.lambda.example
import org.encalmo.utils.JsonUtils.*
import org.encalmo.lambda.ApiGatewayRequest
import org.encalmo.lambda.ApiGatewayResponse
import org.encalmo.lambda.SqsEvent
import java.util.UUID
import org.encalmo.aws.AwsClient
class ExampleLambda3Spec extends TestSuite {
val environment = Map("LAMBDA_RUNTIME_DEBUG_MODE" -> "ON")
test("ExampleLambda3 should respond to generic event") {
val input = """|{
| "functionName": "Greeting",
| "functionInput": {
| "name": "Wroclaw"
| }
|}""".stripMargin
val output = new ExampleLambda3().test(input, environment)
assertEquals(output, """{"greeting":"Hello Wroclaw!"}""")
}
test("ExampleLambda3 should respond to GET /hello/{name}") {
val input = ApiGatewayRequest("GET", "/hello/World").writeAsString
val output = new ExampleLambda3().test(input, environment)
assertEquals(output.readAs[ApiGatewayResponse].body, "Hello World!")
}
test("ExampleLambda3 should respond to POST /hello") {
val input = ApiGatewayRequest("POST", "/hello", "World").writeAsString
val output = new ExampleLambda3().test(input, environment)
assertEquals(output.readAs[ApiGatewayResponse].body, "Hello World!")
}
test("ExampleLambda3 should process SQS events") {
val awsClientStub = AwsClient.newStatefulTestingStub()
val targetSqsQueueUrl = "/foobar"
val input = SqsEvent(Records =
Seq(
SqsEvent.Record(
body = """|{
| "functionName": "SendTargetEvent",
| "functionInput": {
| "name": "Wroclaw"
| }
|}""".stripMargin,
messageId = UUID.randomUUID().toString,
attributes = Map.empty,
eventSource = "",
eventSourceARN = ""
)
)
).writeAsString
new ExampleLambda3(Some(awsClientStub))
.test(
input,
environment + ("TARGET_SQS_QUEUE_URL" -> targetSqsQueueUrl)
)
val targetEvent = awsClientStub.sqs.poll("/foobar")
assert(targetEvent.isDefined)
assertEquals(targetEvent.get._1, "Hello Wroclaw!")
}
}