Giter Site home page Giter Site logo

rvcr's Introduction

rvcr

crates.io

Record-and-replay testing middleware for reqwest http client.

Inspired by:

Builds on top of:

Examples

To record HTTP requests, initialize client like following

  use std::path::PathBuf;
  use reqwest::Client;
  use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
  use rvcr::{VCRMiddleware, VCRMode};

  let mut bundle = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
  bundle.push("tests/resources/replay.vcr.json");

  let middleware: VCRMiddleware = VCRMiddleware::try_from(bundle.clone())
      .unwrap()
      .with_mode(VCRMode::Record);

  let vcr_client: ClientWithMiddleware = ClientBuilder::new(reqwest::Client::new())
      .with(middleware)
      .build();

Now ClientWithMiddleware instance will be recording requests to a file located in tests/resources/replay.vcr.json inside the project.

To use recorded VCR cassette files, replace .with_mode(VCRMode::Record) with .with_mode(VCRMode::Replay), or omit it, since replay is used by default.

Search mode

When replaying, rVCR can skip requests already found when searching for subsequent requests (the default). To disable skipping requests, which is useful, for example, if requests are done in parallel and responses may come in random order, use .with_search(VCRReplaySearch::SearchAll).

VCR cassette fie compression

Sometimes VCR files can be too large and this harder to maintain in a version control system.

To save some space and turn on bzip2 compression for artifacts, use .compression(true) method of the builder.

rvcr's People

Contributors

mksh avatar qaston avatar niclas-ahden avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.