@@ -24,6 +24,21 @@ def compose(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
2424 })
2525"""
2626
27+ async_composition_script = """
28+ from crossplane.function.proto.v1 import run_function_pb2 as fnv1
29+
30+ async def compose(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
31+ rsp.desired.resources["bucket"].resource.update({
32+ "apiVersion": "s3.aws.upbound.io/v1beta2",
33+ "kind": "Bucket",
34+ "spec": {
35+ "forProvider": {
36+ "region": "us-east-1"
37+ }
38+ },
39+ })
40+ """
41+
2742operation_script = """
2843from crossplane.function.proto.v1 import run_function_pb2 as fnv1
2944
@@ -33,6 +48,15 @@ def operate(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
3348 rsp.output["message"] = "Operation completed successfully"
3449"""
3550
51+ async_operation_script = """
52+ from crossplane.function.proto.v1 import run_function_pb2 as fnv1
53+
54+ async def operate(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
55+ # Set output for operation monitoring
56+ rsp.output["result"] = "success"
57+ rsp.output["message"] = "Operation completed successfully"
58+ """
59+
3660both_functions_script = """
3761from crossplane.function.proto.v1 import run_function_pb2 as fnv1
3862
@@ -91,6 +115,31 @@ class TestCase:
91115 context = structpb .Struct (),
92116 ),
93117 ),
118+ TestCase (
119+ reason = "Function should run async composition scripts with await." ,
120+ req = fnv1 .RunFunctionRequest (
121+ input = resource .dict_to_struct ({"script" : async_composition_script }),
122+ ),
123+ want = fnv1 .RunFunctionResponse (
124+ meta = fnv1 .ResponseMeta (ttl = durationpb .Duration (seconds = 60 )),
125+ desired = fnv1 .State (
126+ resources = {
127+ "bucket" : fnv1 .Resource (
128+ resource = resource .dict_to_struct (
129+ {
130+ "apiVersion" : "s3.aws.upbound.io/v1beta2" ,
131+ "kind" : "Bucket" ,
132+ "spec" : {
133+ "forProvider" : {"region" : "us-east-1" }
134+ },
135+ }
136+ )
137+ )
138+ }
139+ ),
140+ context = structpb .Struct (),
141+ ),
142+ ),
94143 ]
95144
96145 runner = fn .FunctionRunner ()
@@ -128,6 +177,23 @@ class TestCase:
128177 ),
129178 ),
130179 ),
180+ TestCase (
181+ reason = "Function should run async operation scripts with await." ,
182+ req = fnv1 .RunFunctionRequest (
183+ input = resource .dict_to_struct ({"script" : async_operation_script }),
184+ ),
185+ want = fnv1 .RunFunctionResponse (
186+ meta = fnv1 .ResponseMeta (ttl = durationpb .Duration (seconds = 60 )),
187+ desired = fnv1 .State (),
188+ context = structpb .Struct (),
189+ output = resource .dict_to_struct (
190+ {
191+ "result" : "success" ,
192+ "message" : "Operation completed successfully" ,
193+ }
194+ ),
195+ ),
196+ ),
131197 ]
132198
133199 runner = fn .FunctionRunner ()
0 commit comments