restRoleAppTest function
The test of the REST role that the CLI keeps in its app_tests/rest_role,
for the apps with the role, whichever module provides it, that among
accepts, or all of them. Each test but one makes a client of its own over
createRestTransport() and runs in real time, against a local server, so
it needs neither the start-up of the app nor a session:
appResttakes its address from.env, a request reaches the server as the code asked it, with no credential that the code did not give, and a relative path without an address fails withnotConfiguredbefore anything is sent;- any status is a reply, which comes back as a response or a failure of a
closed set of reasons, and a connection that fails or breaks, also in a
TLS handshake, is the reason
network, with no query in its hint; - the token goes only to the origin of the address, also after a redirect, which a provider leaves to the client;
- a 401 gets a new token once and repeats once;
GETandHEADrepeat as the role says, keeping toRetry-After, and other methods never do;- a timeout covers a whole attempt, a cancel ends a call at once, and each closes the connection;
- a debug build prints one line for each attempt, and neither the client nor the provider prints or says a token, a query or a body.
The test knows only the role. It gives RestRole.baseAddressKey a value in
.env, so it names the role. Its probe, probeRest() of
integration_test/rest_role/probe.dart, reaches no machine off the device: a
GET and a POST reach a server of its own on the device, an exchange that
has to stop closes its connection, a request over http:// fails as a
connection fails, and an app with an empty .env, as an app of CI has,
says so through the client of the app. The test runs the probe too.
Implementation
Future<MatrixAppTest> restRoleAppTest({
bool Function(MatrixApp app)? among,
}) async =>
MatrixAppTest(
'${await appTestsDirectoryOf('smf_flutter_cli')}/rest_role',
appliesTo: (app) =>
app.hook!.presentRoles.contains(restRole) &&
(among?.call(app) ?? true),
values: (app) => {
'base_address': _restBaseAddress,
'base_key': RestRole.baseAddressKey.name,
},
envValues: (app) => {RestRole.baseAddressKey.name: _restBaseAddress},
roles: {restRole},
startProbe: const MatrixStartProbe(
'integration_test/rest_role/probe.dart',
'probeRest',
),
);