apiTest<T extends ApiService> method

void apiTest<T extends ApiService>(
  1. String name,
  2. FutureOr<void> body(
    1. RestClient client
    ), {
  3. Timeout? timeout,
  4. Object? tags,
  5. Map<String, dynamic>? onPlatform,
  6. int? retry,
  7. Object? skip,
  8. String? testOn,
})

Wrapper for defining api test bodies.

Wrapping the test body function with this method ensures that the test is run in a service zone which provides access to the ServiceResolver required by the resolve function.

This method additionally provides access to a client connected to the selected ApiService of the host.

Implementation

void apiTest<T extends ApiService>(
  String name,
  FutureOr<void> Function(RestClient client) body, {
  dartTest.Timeout? timeout,
  Object? tags,
  Map<String, dynamic>? onPlatform,
  int? retry,
  Object? skip,
  String? testOn,
}) {
  test(
    name,
    () async {
      final api = resolve<T>();
      final client = RestClient.connectHttp2(
        Uri(
          scheme: 'http',
          host: InternetAddress.loopbackIPv4.host,
          port: api.port,
          path: api.basePath,
        ),
      );
      try {
        await body(client);
      } finally {
        await client.close();
      }
    },
    timeout: timeout,
    tags: tags,
    onPlatform: onPlatform,
    retry: retry,
    skip: skip,
    testOn: testOn,
  );
}