Skip to content

Commit

Permalink
Merge of #240
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 5, 2024
2 parents d9c3d45 + 1895139 commit 358da3f
Show file tree
Hide file tree
Showing 21 changed files with 7,976 additions and 1,645 deletions.
10 changes: 6 additions & 4 deletions python/api.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ bring cloud;
bring http;
bring expect;
bring util;
bring fs;
bring "./lib.w" as python;

let bucket = new cloud.Bucket();
let api = new cloud.Api();
api.get("/test", new python.InflightApiEndpointHandler(
path: "./test-assets",
path: fs.join(@dirname, "./test-assets"),
handler: "main.api_handler",
).lift(bucket, id: "bucket", allow: ["put"]));
).lift(bucket, id: "bucket", allow: ["put"]), env: { FOO: "bar" });

test "invokes api handler" {
new std.Test(inflight () => {
let res = http.get("{api.url}/test");
log(Json.stringify(res));
expect.equal(res.status, 200);
expect.equal(res.body, "Hello from Api Handler!");
expect.equal(res.headers["header1"], "value1");
expect.equal(res.headers["foo"], "bar");

util.waitUntil(inflight () => {
return bucket.exists("/test");
});
}
}, timeout: 3m) as "invokes api handler";
7 changes: 4 additions & 3 deletions python/bucket.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ bring cloud;
bring http;
bring expect;
bring util;
bring fs;
bring "./lib.w" as python;

let bucket = new cloud.Bucket();
bucket.onCreate(new python.InflightBucketEvent(
path: "./test-assets",
path: fs.join(@dirname, "./test-assets"),
handler: "main.bucket_oncreate_handler",
).lift(bucket, id: "bucket", allow: ["put"]));

test "invokes bucket on create" {
new std.Test(inflight () => {
bucket.put("key1", "value1");
util.waitUntil(inflight () => {
return bucket.get("key1") == "onCreate";
});
}
}, timeout: 3m) as "invokes bucket on create";
40 changes: 35 additions & 5 deletions python/function.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,54 @@ bring cloud;
bring http;
bring expect;
bring util;
bring dynamodb;
bring sns;
bring ses;
bring fs;
bring "./lib.w" as python;

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.InflightFunction(
path: "./test-assets",
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"],
},
},
), { env: { "FOO": "bar" } });

test "invokes the function" {
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!function1bar");
}
expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValue");
}, timeout: 3m) as "invokes the function";
20 changes: 15 additions & 5 deletions python/lib.w
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub class InflightFunction impl cloud.IFunctionHandler {

let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.Inflight(props);
let implementation = new sim.Inflight(props);
nodeof(implementation).hidden = true;
this.inner = implementation;
} elif target == "tf-aws" {
this.inner = new aws.Inflight_tfaws(props);
} else {
Expand Down Expand Up @@ -46,7 +48,9 @@ pub class InflightQueueConsumer impl cloud.IQueueSetConsumerHandler {

let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.Inflight(props);
let implementation = new sim.Inflight(props);
nodeof(implementation).hidden = true;
this.inner = implementation;
} elif target == "tf-aws" {
this.inner = new aws.Inflight_tfaws(props);
} else {
Expand Down Expand Up @@ -76,7 +80,9 @@ pub class InflightTopicOnMessage impl cloud.ITopicOnMessageHandler {

let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.Inflight(props);
let implementation = new sim.Inflight(props);
nodeof(implementation).hidden = true;
this.inner = implementation;
} elif target == "tf-aws" {
this.inner = new aws.Inflight_tfaws(props);
} else {
Expand Down Expand Up @@ -106,7 +112,9 @@ pub class InflightBucketEvent impl cloud.IBucketEventHandler {

let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.BucketEventInflight(props);
let implementation = new sim.BucketEventInflight(props);
nodeof(implementation).hidden = true;
this.inner = implementation;
} elif target == "tf-aws" {
this.inner = new aws.Inflight_tfaws(props);
} else {
Expand Down Expand Up @@ -136,7 +144,9 @@ pub class InflightApiEndpointHandler impl cloud.IApiEndpointHandler {

let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new simapi.InflightApiEndpointHandler(props);
let implementation = new simapi.InflightApiEndpointHandler(props);
nodeof(implementation).hidden = true;
this.inner = implementation;
} elif target == "tf-aws" {
this.inner = new tfawsapi.InflightApiEndpointHandler_aws(props);
} else {
Expand Down
Loading

0 comments on commit 358da3f

Please sign in to comment.