testFunction method
Tests a CloudFront function.
To test a function, you provide an event object that represents an HTTP request or response that your CloudFront distribution could receive in production. CloudFront runs the function, passing it the event object that you provided, and returns the function's result (the modified event object) in the response. The response also contains function logs and error messages, if any exist. For more information about testing functions, see Testing functions in the Amazon CloudFront Developer Guide.
To test a function, you provide the function's name and version
(ETag value) along with the event object. To get the
function's name and version, you can use ListFunctions and
DescribeFunction.
May throw InvalidArgument.
May throw InvalidIfMatchVersion.
May throw NoSuchFunctionExists.
May throw TestFunctionFailed.
May throw UnsupportedOperation.
Parameter eventObject :
The event object to test the function with. For more information about the
structure of the event object, see Testing
functions in the Amazon CloudFront Developer Guide.
Parameter ifMatch :
The current version (ETag value) of the function that you are
testing, which you can get using DescribeFunction.
Parameter name :
The name of the function that you are testing.
Parameter stage :
The stage of the function that you are testing, either
DEVELOPMENT or LIVE.
Implementation
Future<TestFunctionResult> testFunction({
required Uint8List eventObject,
required String ifMatch,
required String name,
FunctionStage? stage,
}) async {
final headers = <String, String>{
'If-Match': ifMatch.toString(),
};
final $result = await _protocol.sendRaw(
method: 'POST',
requestUri: '/2020-05-31/function/${Uri.encodeComponent(name)}/test',
headers: headers,
payload: TestFunctionRequest(
eventObject: eventObject,
ifMatch: ifMatch,
name: name,
stage: stage)
.toXml('TestFunctionRequest'),
exceptionFnMap: _exceptionFns,
);
final $elem = await _s.xmlFromResponse($result);
return TestFunctionResult(
testResult: TestResult.fromXml($elem),
);
}