iostub 0.1.0

A ready to use std::io::Read stub to write test suites
Documentation
  • Coverage
  • 0%
    0 out of 1 items documented0 out of 0 items with examples
  • Size
  • Source code size: 8.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 139.95 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • JDRobotter/iostub
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JDRobotter

iostub

iostub is a small and ready to use rust library to stub std::io::Read in test suites.

usage

IOStub allow you to provide a object implementing std::io::Read which can be consumed by your test subject and still allow you to push data or errors trough it.

        let mut stub = IOStub::new();
        let mut cr = ConsumeReader::new(stub.clone());

        stub.push_read(b"otters");
        stub.push_read(b"are");
        stub.push_read(b"amazing");
        let rv = cr.read_all();
        assert!(rv.is_ok());
        assert_eq!(rv.unwrap(), Vec::from(b"ottersareamazing"));

        let rv = cr.read_all();
        assert!(rv.is_ok());
        assert_eq!(rv.unwrap(), Vec::from(b""));

        stub.push_read(b"from");
        stub.push_read(b"otter");
        stub.push_read(b"space");
        let rv = cr.read_all();
        assert!(rv.is_ok());
        assert_eq!(rv.unwrap(), Vec::from(b"fromotterspace"))

        stub.push_read_error(Error::new(ErrorKind::TimedOut, "xxx"));
        let rv = cr.read_one();
        assert!(rv.is_err());
        let e = rv.unwrap_err();
        assert_eq!(e.kind(), ErrorKind::TimedOut);

caution

This library was designed for testing purposes and is not optimised for anything else.