Movatterモバイル変換


[0]ホーム

URL:


iotest

packagestandard library
go1.25.2Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:5Imported by:104

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package iotest implements Readers and Writers useful mainly for testing.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrTimeout =errors.New("timeout")

ErrTimeout is a fake timeout error.

Functions

funcDataErrReader

func DataErrReader(rio.Reader)io.Reader

DataErrReader changes the way errors are handled by a Reader. Normally, aReader returns an error (typically EOF) from the first Read call after thelast piece of data is read. DataErrReader wraps a Reader and changes itsbehavior so the final error is returned along with the final data, insteadof in the first call after the final data.

funcErrReaderadded ingo1.16

func ErrReader(errerror)io.Reader

ErrReader returns anio.Reader that returns 0, err from all Read calls.

Example
package mainimport ("errors""fmt""testing/iotest")func main() {// A reader that always returns a custom error.r := iotest.ErrReader(errors.New("custom error"))n, err := r.Read(nil)fmt.Printf("n:   %d\nerr: %q\n", n, err)}
Output:n:   0err: "custom error"

funcHalfReader

func HalfReader(rio.Reader)io.Reader

HalfReader returns a Reader that implements Readby reading half as many requested bytes from r.

funcNewReadLogger

func NewReadLogger(prefixstring, rio.Reader)io.Reader

NewReadLogger returns a reader that behaves like r exceptthat it logs (usinglog.Printf) each read to standard error,printing the prefix and the hexadecimal data read.

funcNewWriteLogger

func NewWriteLogger(prefixstring, wio.Writer)io.Writer

NewWriteLogger returns a writer that behaves like w exceptthat it logs (usinglog.Printf) each write to standard error,printing the prefix and the hexadecimal data written.

funcOneByteReader

func OneByteReader(rio.Reader)io.Reader

OneByteReader returns a Reader that implementseach non-empty Read by reading one byte from r.

funcTestReaderadded ingo1.16

func TestReader(rio.Reader, content []byte)error

TestReader tests that reading from r returns the expected file content.It does reads of different sizes, until EOF.If r implementsio.ReaderAt orio.Seeker, TestReader also checksthat those operations behave as they should.

If TestReader finds any misbehaviors, it returns an error reporting them.The error text may span multiple lines.

funcTimeoutReader

func TimeoutReader(rio.Reader)io.Reader

TimeoutReader returnsErrTimeout on the second readwith no data. Subsequent calls to read succeed.

funcTruncateWriter

func TruncateWriter(wio.Writer, nint64)io.Writer

TruncateWriter returns a Writer that writes to wbut stops silently after n bytes.

Types

This section is empty.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp