filetestutil

package
v0.0.0-...-e2c53ed Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

Package cloudeng.io/file/filetestutil

import cloudeng.io/file/filetestutil

Functions

Func CompareFS
func CompareFS(a, b file.FS) error

CompareFS returns nil if the two instances of fs.FS contain exactly the same files and file contents.

Func CompareFileInfo
func CompareFileInfo(a, b file.InfoList) error
Func Contents
func Contents(fs file.FS) map[string][]byte

Contents returns the contents stored in the mock fs.FS.

Func NewFile
func NewFile(rd io.ReadCloser, info fs.FileInfo) fs.File
Func NewMockFS
func NewMockFS(opts ...FSOption) file.FS

NewMockFS returns an new mock instance of file.FS as per the specified options.

Func WrapEmbedFS
func WrapEmbedFS(fs embed.FS) file.FS

WrapEmbedFS wraps an embed.FS to implement file.FS.

Types

Type BufferCloser
type BufferCloser struct {
	*bytes.Buffer
}

BufferCloser adds an io.Closer to bytes.Buffer.

Methods
func (bc *BufferCloser) Close() error
Type FSOption
type FSOption func(o *fsOptions)

FSOption represents an option to configure a new mock instance of fs.FS.

Functions
func FSErrorOnly(err error) FSOption

FSErrorOnly requests a mock FS that always returns err.

func FSScheme(s string) FSOption
func FSWithConstantContents(val []byte, repeat int) FSOption

FSWithConstantContents requests a mock FS that will return files of a random size (up to maxSize) with random contents.

func FSWithRandomContents(src rand.Source, maxSize int) FSOption

FSWithRandomContents requests a mock FS that will return files of a random size (up to maxSize) with random contents.

func FSWithRandomContentsAfterRetry(src rand.Source, maxSize, numRetries int, err error) FSOption

FSWithRandomContentsAfterRetry is like FSWithRandomContents but will return err, numRetries times before succeeding.

Type WriteFS
type WriteFS struct {
	sync.Mutex
	// contains filtered or unexported fields
}
Functions
func NewWriteFS() *WriteFS
Methods
func (wfs *WriteFS) Create(_ context.Context, name string, filemode fs.FileMode) (io.WriteCloser, error)
func (wfs *WriteFS) Open(name string) (fs.File, error)
func (wfs *WriteFS) OpenCtx(_ context.Context, name string) (fs.File, error)
func (mfs *WriteFS) Scheme() string

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareFS

func CompareFS(a, b file.FS) error

CompareFS returns nil if the two instances of fs.FS contain exactly the same files and file contents.

func CompareFileInfo

func CompareFileInfo(a, b file.InfoList) error

func Contents

func Contents(fs file.FS) map[string][]byte

Contents returns the contents stored in the mock fs.FS.

func NewFile

func NewFile(rd io.ReadCloser, info fs.FileInfo) fs.File

func NewMockFS

func NewMockFS(opts ...FSOption) file.FS

NewMockFS returns an new mock instance of file.FS as per the specified options.

func WrapEmbedFS

func WrapEmbedFS(fs embed.FS) file.FS

WrapEmbedFS wraps an embed.FS to implement file.FS.

Types

type BufferCloser

type BufferCloser struct {
	*bytes.Buffer
}

BufferCloser adds an io.Closer to bytes.Buffer.

func (*BufferCloser) Close

func (bc *BufferCloser) Close() error

type FSOption

type FSOption func(o *fsOptions)

FSOption represents an option to configure a new mock instance of fs.FS.

func FSErrorOnly

func FSErrorOnly(err error) FSOption

FSErrorOnly requests a mock FS that always returns err.

func FSScheme

func FSScheme(s string) FSOption

func FSWithConstantContents

func FSWithConstantContents(val []byte, repeat int) FSOption

FSWithConstantContents requests a mock FS that will return files of a random size (up to maxSize) with random contents.

func FSWithRandomContents

func FSWithRandomContents(src rand.Source, maxSize int) FSOption

FSWithRandomContents requests a mock FS that will return files of a random size (up to maxSize) with random contents.

func FSWithRandomContentsAfterRetry

func FSWithRandomContentsAfterRetry(src rand.Source, maxSize, numRetries int, err error) FSOption

FSWithRandomContentsAfterRetry is like FSWithRandomContents but will return err, numRetries times before succeeding.

type WriteFS

type WriteFS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWriteFS

func NewWriteFS() *WriteFS

func (*WriteFS) Create

func (wfs *WriteFS) Create(_ context.Context, name string, filemode fs.FileMode) (io.WriteCloser, error)

func (*WriteFS) Open

func (wfs *WriteFS) Open(name string) (fs.File, error)

func (*WriteFS) OpenCtx

func (wfs *WriteFS) OpenCtx(_ context.Context, name string) (fs.File, error)

func (*WriteFS) Scheme

func (mfs *WriteFS) Scheme() string

Jump to

Keyboard shortcuts

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