iosemantic

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2020 License: MIT Imports: 7 Imported by: 0

README

iosemantic

GoDoc MIT license Go Report Card

A testing library containing helper function to verify that io.Readers and io.Writers implement their respective specifications.

An example usage is DRFS, where I implemented a file abstraction and use this library to ensure my implementation has the correct io semantics.

Example

func TestMyCustomFileBackendSemantics(t *testing.T) {
    var file = NewCustomFileBackend()
    iosemantic.ImplementsReader(t, file)
    iosemantic.ImplementsWriter(t, file)
    iosemantic.ImplementsWriterAt(t, file)
}

Caveats

iosemantic only verifies that the interfaces match their specifications, not that the input and output buffers remain consistent. You will still need to write tests to verify your business logic.

Stability

The current API will remain consistent. Functions accepting respective option structs may be expanded on by adding options to these structs, where unset fields are set to sane defaults.

Documentation

Overview

Package iosemantic contains helper functions to verify that io.Readers, io.Writers and other io interfaces adhere to the given specifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImplementsReader

func ImplementsReader(t *testing.T, reader io.Reader) bool

ImplementsReader verifies the following properties for a reader:

  1. n <= len(p) (where p is the buffer passed to the Read method).
  2. if 0 < n < len(p), an error is returned; or the next call to read returns 0, io.EOF
  3. if len(p) == 0, n == 0

Use ImplementsReaderOpts for more control over the test suite.

func ImplementsReaderAt

func ImplementsReaderAt(t *testing.T, reader io.ReaderAt, length int64) bool

ImplementsReaderAt verifies the following properties for a io.ReaderAt:

1. n <= len(p) (where p is the buffer passed to the Read method). 2. if 0 < n < len(p), an error is returned; 3. if len(p) == 0, n == 0 4. Parallel ReadAt calls do not result in errors.

ImplementsReaderAt is a more strict version of ImplementsReader, just like the semantics of io.Reader and io.ReaderAt. Use ImplementsReaderAtOpts for more control over the test suite.

func ImplementsReaderAtOpts

func ImplementsReaderAtOpts(t *testing.T, reader io.ReaderAt, length int64, opts ReaderAtOpts) bool

ImplementsReaderAtOpts uses providing options to perform ImplementsReaderAt.

func ImplementsReaderFrom

func ImplementsReaderFrom(t *testing.T, reader io.ReaderFrom) bool

ImplementsReaderFrom verifies the following properties for a reader:

1. The ReaderFrom consumes the input until an error is encountered. 2. io.EOF is not returned.

Use ImplementsReaderFromOpts for more control over the test suite.

func ImplementsReaderFromOpts

func ImplementsReaderFromOpts(t *testing.T, reader io.ReaderFrom, opts ReaderFromOpts) bool

ImplementsReaderFromOpts uses providing options to perform ImplementsReaderFrom.

func ImplementsReaderOpts

func ImplementsReaderOpts(t *testing.T, reader io.Reader, opts ReaderOpts) bool

ImplementsReaderOpts uses providing options to perform ImplementsReader.

func ImplementsWriter

func ImplementsWriter(t *testing.T, writer io.Writer) bool

ImplementsWriter verifies the following properties for a writer:

1. 0 <= n <= len(p) where p is the buffer being written from. 2. if n < len(p), err != nil.

Use ImplementsWriterOpts for more control over the test suite.

func ImplementsWriterAt

func ImplementsWriterAt(t *testing.T, writer io.WriterAt, length int64) bool

ImplementsWriterAt verifies the following properties for a writer:

1. 0 <= n <= len(p) where p is the buffer being written from. 2. if n < len(p), err != nil. 3. No error is returned during parallel WriteAt calls on the same destination if the ranges do not overlap.

Use ImplementsWriterAtOpts for more control over the test suite.

func ImplementsWriterAtOpts

func ImplementsWriterAtOpts(t *testing.T, writer io.WriterAt, length int64, opts WriterAtOpts) bool

ImplementsWriterAtOpts uses providing options to perform ImplementsWriterAt.

func ImplementsWriterOpts

func ImplementsWriterOpts(t *testing.T, writer io.Writer, opts WriterOpts) bool

ImplementsWriterOpts uses providing options to perform ImplementsWriter.

func ImplementsWriterTo

func ImplementsWriterTo(t *testing.T, writer io.WriterTo) bool

ImplementsWriterTo verifies the following properties for a reader:

1. The WriterTo writes to the writer until it is finished, or an error is encountered. 2. Any error is returned.

Use ImplementsWriterToOpts for more control over the test suite.

func ImplementsWriterToOpts

func ImplementsWriterToOpts(t *testing.T, writer io.WriterTo, opts WriterToOpts) bool

ImplementsWriterToOpts uses providing options to perform ImplementsWriterTo.

Types

type ReaderAtOpts

type ReaderAtOpts struct {
	BufferSize int
}

ReaderAtOpts defines fine tunes controls for the ImplementsReaderAtOpts test.

type ReaderFromOpts

type ReaderFromOpts struct {
	BufferSize int
}

ReaderFromOpts defines fine tunes controls for the ImplementsReaderFromOpts test.

type ReaderOpts

type ReaderOpts struct {
	BufferSize int
}

ReaderOpts defines fine tunes controls for the ImplementsReaderOpts test.

type WriterAtOpts

type WriterAtOpts struct {
	BufferSize int
}

WriterAtOpts defines fine tunes controls for the ImplementsWriterAtOpts test.

type WriterOpts

type WriterOpts struct {
	BufferSize int
}

WriterOpts defines fine tunes controls for the ImplementsWriterOpts test.

type WriterToOpts

type WriterToOpts struct {
	BufferSize int
}

WriterToOpts defines fine tunes controls for the ImplementsWriterToOpts test.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL