-
Notifications
You must be signed in to change notification settings - Fork 14
/
function.test.w
67 lines (62 loc) · 1.42 KB
/
function.test.w
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
bring cloud;
bring http;
bring expect;
bring util;
bring dynamodb;
bring sns;
bring ses;
bring fs;
bring "./lib.w" as python;
class CustomLiftable impl python.ILiftable {
pub liftData(): Json {
return {
"info": "CustomData",
};
}
}
let table = new dynamodb.Table(
attributes: [
{
name: "id",
type: "S",
},
],
hashKey: "id",
) as "table1";
let emailClient = new ses.EmailService({});
let mobileClient = new sns.MobileNotifications();
let bucket = new cloud.Bucket();
bucket.addObject("test.txt", "Hello, world!");
let func = new cloud.Function(new python.InflightFunctionHandler(
path: fs.join(@dirname, "./test-assets"),
handler: "main.handler",
lift: {
"bucket": {
obj: bucket,
allow: ["get", "put"],
},
"table": {
obj: table,
allow: ["get", "put"],
},
"sms": {
obj: mobileClient,
allow: ["publish"],
},
"email": {
obj: emailClient,
allow: ["sendEmail"],
},
"custom": {
obj: new CustomLiftable(),
allow: [],
}
},
), { env: { "FOO": "bar" } });
new std.Test(inflight () => {
table.put(Item: { id: "test", body: "dynamoDbValue" });
let res = func.invoke("function1");
log("res: {res ?? "null"}");
expect.equal(Json.parse(res!).get("body"), "Hello!");
expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValueCustomData");
}, timeout: 3m) as "invokes the function";