Documentation
¶
Index ¶
- type CloseErrorReadCloser
- type CloseErrorWriteCloser
- type ErrorFile
- func (e *ErrorFile) Close() error
- func (e *ErrorFile) Read(p []byte) (int, error)
- func (e *ErrorFile) ReadDir(count int) ([]fs.DirEntry, error)
- func (e *ErrorFile) Seek(offset int64, whence int) (int64, error)
- func (e *ErrorFile) Stat() (os.FileInfo, error)
- func (e *ErrorFile) Write(p []byte) (n int, err error)
- type ErrorHasher
- type ErrorReadWriteCloser
- type ErrorWriteAfterN
- type ErrorWriteCloser
- type File
- func (f *File) Bytes() []byte
- func (f *File) Close() error
- func (f *File) Read(p []byte) (int, error)
- func (f *File) ReadDir(count int) ([]fs.DirEntry, error)
- func (f *File) Reset()
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Stat() (os.FileInfo, error)
- func (f *File) Truncate(n int)
- func (f *File) Write(p []byte) (n int, err error)
- type WriteCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloseErrorReadCloser ¶
type CloseErrorReadCloser struct {
// contains filtered or unexported fields
}
CloseErrorReadCloser is a mock io.ReadCloser where only the Close() method returns an error. This is useful for testing scenarios where reads succeed but closing fails.
func NewCloseErrorReadCloser ¶
func NewCloseErrorReadCloser(r io.Reader, err error) *CloseErrorReadCloser
NewCloseErrorReadCloser creates a new ReadCloser that reads successfully but returns an error when Close() is called. This simulates partial failure scenarios.
func (*CloseErrorReadCloser) Close ¶
func (c *CloseErrorReadCloser) Close() error
Close always returns the configured error, simulating a close failure while allowing reads to succeed.
type CloseErrorWriteCloser ¶
type CloseErrorWriteCloser struct {
// contains filtered or unexported fields
}
CloseErrorWriteCloser is a mock io.WriteCloser where only the Close() method returns an error. This is useful for testing scenarios where writes succeed but closing fails.
func NewCloseErrorWriteCloser ¶
func NewCloseErrorWriteCloser(w io.Writer, err error) *CloseErrorWriteCloser
NewCloseErrorWriteCloser creates a new WriteCloser that writes successfully but returns an error when Close() is called. This simulates partial failure scenarios.
func (*CloseErrorWriteCloser) Close ¶
func (c *CloseErrorWriteCloser) Close() error
Close always returns the configured error, simulating a close failure while allowing writes to succeed.
type ErrorFile ¶
type ErrorFile struct {
// contains filtered or unexported fields
}
ErrorFile is a mock file implementation that always returns errors. This is useful for testing error handling paths in code that operates on files.
func NewErrorFile ¶
NewErrorFile creates a new error file that will return the specified error for all file operations. This is commonly used to test error scenarios.
func (*ErrorFile) Close ¶
Close always returns the configured error, simulating a file close failure.
func (*ErrorFile) ReadDir ¶
ReadDir always returns the configured error, simulating a directory read failure.
type ErrorHasher ¶
type ErrorHasher struct {
// contains filtered or unexported fields
}
ErrorHasher is a mock implementation of hash.Hash that can return errors on Write operations. This is useful for testing error handling in code that uses hash.Hash interfaces.
func NewErrorHasher ¶
func NewErrorHasher(writeErr error) *ErrorHasher
NewErrorHasher creates a new ErrorHasher that will return the specified error when Write() is called. This is useful for testing hash write error scenarios.
func (*ErrorHasher) BlockSize ¶
func (h *ErrorHasher) BlockSize() int
BlockSize implements the hash.Hash interface and returns a mock block size.
func (*ErrorHasher) Reset ¶
func (h *ErrorHasher) Reset()
Reset implements the hash.Hash interface but does nothing in this mock.
func (*ErrorHasher) Size ¶
func (h *ErrorHasher) Size() int
Size implements the hash.Hash interface and returns a mock hash size.
func (*ErrorHasher) Sum ¶
func (h *ErrorHasher) Sum(b []byte) []byte
Sum implements the hash.Hash interface and returns a mock hash value. This always succeeds and returns a unique mock hash for testing.
type ErrorReadWriteCloser ¶
type ErrorReadWriteCloser struct {
Err error // The error to return for all read, write, and close operations
}
ErrorReadWriteCloser is a mock that implements io.Reader, io.Writer, and io.Closer interfaces, always returning the specified error for all operations. This is useful for testing scenarios where all I/O operations fail, such as network failures or corrupted streams.
func NewErrorReadWriteCloser ¶
func NewErrorReadWriteCloser(err error) *ErrorReadWriteCloser
NewErrorReadWriteCloser creates a new ErrorReadWriteCloser that will return the specified error for all read, write, and close operations. This mock is particularly useful for testing error handling in streaming operations where all I/O methods need to fail consistently.
func (*ErrorReadWriteCloser) Close ¶
func (e *ErrorReadWriteCloser) Close() error
Close always returns the configured error, simulating a close failure. This method implements the io.Closer interface for consistent error testing.
type ErrorWriteAfterN ¶
type ErrorWriteAfterN struct {
N int // Number of successful writes before returning error
Err error // The error to return after N successful writes
// contains filtered or unexported fields
}
ErrorWriteAfterN is a mock io.Writer that succeeds for the first N writes and then returns an error for all subsequent writes. This is useful for testing scenarios where a writer works initially but fails after a certain number of operations, such as disk full errors or connection drops.
func NewErrorWriteAfterN ¶
func NewErrorWriteAfterN(n int, err error) *ErrorWriteAfterN
NewErrorWriteAfterN creates a new ErrorWriteAfterN that will allow N successful writes before returning the specified error. This is commonly used to test partial write scenarios and error recovery in streaming operations.
func (*ErrorWriteAfterN) Reset ¶
func (e *ErrorWriteAfterN) Reset()
Reset resets the write counter and total bytes, allowing the mock to be reused.
func (*ErrorWriteAfterN) TotalBytes ¶
func (e *ErrorWriteAfterN) TotalBytes() int
TotalBytes returns the total number of bytes successfully written (for testing).
func (*ErrorWriteAfterN) Write ¶
func (e *ErrorWriteAfterN) Write(p []byte) (int, error)
Write implements the io.Writer interface. It succeeds for the first N calls and returns the configured error for all subsequent calls.
func (*ErrorWriteAfterN) WriteCount ¶
func (e *ErrorWriteAfterN) WriteCount() int
WriteCount returns the number of write operations attempted (for testing).
type ErrorWriteCloser ¶
type ErrorWriteCloser struct {
// contains filtered or unexported fields
}
ErrorWriteCloser is a mock io.WriteCloser that always returns errors. Useful for testing error handling in code that writes to files or other writers.
func NewErrorWriteCloser ¶
func NewErrorWriteCloser(err error) *ErrorWriteCloser
NewErrorWriteCloser creates a new error WriteCloser that will return the specified error for all write and close operations.
func (*ErrorWriteCloser) Close ¶
func (e *ErrorWriteCloser) Close() error
Close always returns the configured error, simulating a close failure.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a mock implementation of the fs.File interface for testing purposes. It provides an in-memory file representation that can be used to simulate file operations without touching the actual file system.
func NewFile ¶
NewFile creates a new mock file with the specified data and name. This function is commonly used in tests to create file-like objects that can be passed to functions expecting file interfaces.
func (*File) Close ¶
Close implements the io.Closer interface for mock file operations. Marks the file as closed, preventing further read operations.
func (*File) Read ¶
Read implements the io.Reader interface for mock file operations. It reads data from the current position and advances the position accordingly. Returns os.ErrClosed if the file has been closed, or io.EOF when reaching the end.
func (*File) ReadDir ¶
ReadDir implements the fs.ReadDirFile interface. Since this mock represents a regular file, not a directory, it always returns an error.
func (*File) Seek ¶
Seek implements the io.Seeker interface for mock file operations. Allows positioning the file pointer at different locations within the file. Supports seeking from start, current position, or end of file.
func (*File) Stat ¶
Stat returns file information for the mock file. Creates a fileInfo object with the file's name and size based on data length.
type WriteCloser ¶
type WriteCloser struct {
// contains filtered or unexported fields
}
WriteCloser is a mock implementation of io.WriteCloser for testing purposes. It wraps an io.Writer and adds close functionality with state tracking.
func NewWriteCloser ¶
func NewWriteCloser(w io.Writer) *WriteCloser
NewWriteCloser creates a new mock WriteCloser that wraps the provided io.Writer. This is useful for testing code that requires both write and close operations.
func (*WriteCloser) Close ¶
func (w *WriteCloser) Close() error
Close implements the io.Closer interface for the mock WriteCloser. Marks the WriteCloser as closed and prevents further write operations.