test method

Future<void> test(
  1. MockServerFactory factory,
  2. RequestTestFunction testFunction
)

Implementation

Future<void> test(MockServerFactory factory, RequestTestFunction testFunction) async {
  final pactBuilder = PactBuilder("mock-consumer", "mock-provider")
    ..stateBuilders.add(_stateBuilder);
  final pact = PactRepository._createHeader(pactBuilder);
  PactRepository._mergeInteractions(pactBuilder, pact);
  final server = factory.createMockServer(pact.interactions[0]);
  try {
    await testFunction(server);
    _stateBuilder._tested = true;
    if (!server.hasMatched()) {
      hasErrors = true;
      final mismatchJson = server.getMismatchJson();
      throw PactMatchingException(mismatchJson);
    }
  } finally {
    factory.closeServer(server);
  }
}