fileio

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package fileio is a generated GoMock package.

Index

Constants

View Source
const (
	// DefaultDirectoryPermissions houses the default mode to use when no directory permissions are provided
	DefaultDirectoryPermissions os.FileMode = 0o755
	// defaultFilePermissions houses the default mode to use when no file permissions are provided
	DefaultFilePermissions os.FileMode = 0o644
	// DefaultExecutablePermissions houses the default mode to use for executable files
	DefaultExecutablePermissions os.FileMode = 0o755
)

Variables

This section is empty.

Functions

func DecodeContent added in v0.6.0

func DecodeContent(content string, encoding *v1alpha1.EncodingType) ([]byte,
	error)

DecodeContents decodes the content based on the encoding type and returns the decoded content as a byte slice.

func IsNotExist added in v0.4.0

func IsNotExist(err error) bool

IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist.

func NewReader

func NewReader() *reader

New creates a new writer

func NewWriter

func NewWriter() *writer

New creates a new writer

func WriteTmpFile added in v0.9.0

func WriteTmpFile(rw ReadWriter, prefix, filename string, content []byte, perm os.FileMode) (path string, cleanup func(), err error)

WriteTmpFile writes the given content to a temporary file with the specified name prefix. It returns the path to the tmp file and a cleanup function to remove it.

Types

type FileOption added in v0.3.0

type FileOption func(*fileOptions)

func WithGid added in v0.3.0

func WithGid(gid int) FileOption

WithGid sets the gid for the file.

func WithUid added in v0.3.0

func WithUid(uid int) FileOption

WithUid sets the uid for the file.

type ManagedFile

type ManagedFile interface {
	Path() string
	Exists() (bool, error)
	IsUpToDate() (bool, error)
	Write() error
}

type MockManagedFile

type MockManagedFile struct {
	// contains filtered or unexported fields
}

MockManagedFile is a mock of ManagedFile interface.

func NewMockManagedFile

func NewMockManagedFile(ctrl *gomock.Controller) *MockManagedFile

NewMockManagedFile creates a new mock instance.

func (*MockManagedFile) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockManagedFile) Exists

func (m *MockManagedFile) Exists() (bool, error)

Exists mocks base method.

func (*MockManagedFile) IsUpToDate

func (m *MockManagedFile) IsUpToDate() (bool, error)

IsUpToDate mocks base method.

func (*MockManagedFile) Path

func (m *MockManagedFile) Path() string

Path mocks base method.

func (*MockManagedFile) Write

func (m *MockManagedFile) Write() error

Write mocks base method.

type MockManagedFileMockRecorder

type MockManagedFileMockRecorder struct {
	// contains filtered or unexported fields
}

MockManagedFileMockRecorder is the mock recorder for MockManagedFile.

func (*MockManagedFileMockRecorder) Exists

func (mr *MockManagedFileMockRecorder) Exists() *gomock.Call

Exists indicates an expected call of Exists.

func (*MockManagedFileMockRecorder) IsUpToDate

func (mr *MockManagedFileMockRecorder) IsUpToDate() *gomock.Call

IsUpToDate indicates an expected call of IsUpToDate.

func (*MockManagedFileMockRecorder) Path

Path indicates an expected call of Path.

func (*MockManagedFileMockRecorder) Write

Write indicates an expected call of Write.

type MockReadWriter

type MockReadWriter struct {
	// contains filtered or unexported fields
}

MockReadWriter is a mock of ReadWriter interface.

func NewMockReadWriter

func NewMockReadWriter(ctrl *gomock.Controller) *MockReadWriter

NewMockReadWriter creates a new mock instance.

func (*MockReadWriter) CopyFile

func (m *MockReadWriter) CopyFile(src, dst string) error

CopyFile mocks base method.

func (*MockReadWriter) CreateManagedFile

func (m *MockReadWriter) CreateManagedFile(file v1alpha1.FileSpec) (ManagedFile, error)

CreateManagedFile mocks base method.

func (*MockReadWriter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockReadWriter) MkdirAll added in v0.3.0

func (m *MockReadWriter) MkdirAll(path string, perm fs.FileMode) error

MkdirAll mocks base method.

func (*MockReadWriter) MkdirTemp added in v0.6.0

func (m *MockReadWriter) MkdirTemp(prefix string) (string, error)

MkdirTemp mocks base method.

func (*MockReadWriter) OverwriteAndWipe added in v0.4.0

func (m *MockReadWriter) OverwriteAndWipe(file string) error

OverwriteAndWipe mocks base method.

func (*MockReadWriter) PathExists added in v0.4.0

func (m *MockReadWriter) PathExists(path string, opts ...PathExistsOption) (bool, error)

PathExists mocks base method.

func (*MockReadWriter) PathFor

func (m *MockReadWriter) PathFor(filePath string) string

PathFor mocks base method.

func (*MockReadWriter) ReadDir added in v0.3.0

func (m *MockReadWriter) ReadDir(dirPath string) ([]fs.DirEntry, error)

ReadDir mocks base method.

func (*MockReadWriter) ReadFile

func (m *MockReadWriter) ReadFile(filePath string) ([]byte, error)

ReadFile mocks base method.

func (*MockReadWriter) RemoveAll added in v0.3.0

func (m *MockReadWriter) RemoveAll(path string) error

RemoveAll mocks base method.

func (*MockReadWriter) RemoveContents added in v0.8.1

func (m *MockReadWriter) RemoveContents(path string) error

RemoveContents mocks base method.

func (*MockReadWriter) RemoveFile

func (m *MockReadWriter) RemoveFile(file string) error

RemoveFile mocks base method.

func (*MockReadWriter) SetRootdir

func (m *MockReadWriter) SetRootdir(path string)

SetRootdir mocks base method.

func (*MockReadWriter) WriteFile

func (m *MockReadWriter) WriteFile(name string, data []byte, perm fs.FileMode, opts ...FileOption) error

WriteFile mocks base method.

type MockReadWriterMockRecorder

type MockReadWriterMockRecorder struct {
	// contains filtered or unexported fields
}

MockReadWriterMockRecorder is the mock recorder for MockReadWriter.

func (*MockReadWriterMockRecorder) CopyFile

func (mr *MockReadWriterMockRecorder) CopyFile(src, dst any) *gomock.Call

CopyFile indicates an expected call of CopyFile.

func (*MockReadWriterMockRecorder) CreateManagedFile

func (mr *MockReadWriterMockRecorder) CreateManagedFile(file any) *gomock.Call

CreateManagedFile indicates an expected call of CreateManagedFile.

func (*MockReadWriterMockRecorder) MkdirAll added in v0.3.0

func (mr *MockReadWriterMockRecorder) MkdirAll(path, perm any) *gomock.Call

MkdirAll indicates an expected call of MkdirAll.

func (*MockReadWriterMockRecorder) MkdirTemp added in v0.6.0

func (mr *MockReadWriterMockRecorder) MkdirTemp(prefix any) *gomock.Call

MkdirTemp indicates an expected call of MkdirTemp.

func (*MockReadWriterMockRecorder) OverwriteAndWipe added in v0.4.0

func (mr *MockReadWriterMockRecorder) OverwriteAndWipe(file any) *gomock.Call

OverwriteAndWipe indicates an expected call of OverwriteAndWipe.

func (*MockReadWriterMockRecorder) PathExists added in v0.4.0

func (mr *MockReadWriterMockRecorder) PathExists(path any, opts ...any) *gomock.Call

PathExists indicates an expected call of PathExists.

func (*MockReadWriterMockRecorder) PathFor

func (mr *MockReadWriterMockRecorder) PathFor(filePath any) *gomock.Call

PathFor indicates an expected call of PathFor.

func (*MockReadWriterMockRecorder) ReadDir added in v0.3.0

func (mr *MockReadWriterMockRecorder) ReadDir(dirPath any) *gomock.Call

ReadDir indicates an expected call of ReadDir.

func (*MockReadWriterMockRecorder) ReadFile

func (mr *MockReadWriterMockRecorder) ReadFile(filePath any) *gomock.Call

ReadFile indicates an expected call of ReadFile.

func (*MockReadWriterMockRecorder) RemoveAll added in v0.3.0

func (mr *MockReadWriterMockRecorder) RemoveAll(path any) *gomock.Call

RemoveAll indicates an expected call of RemoveAll.

func (*MockReadWriterMockRecorder) RemoveContents added in v0.8.1

func (mr *MockReadWriterMockRecorder) RemoveContents(path any) *gomock.Call

RemoveContents indicates an expected call of RemoveContents.

func (*MockReadWriterMockRecorder) RemoveFile

func (mr *MockReadWriterMockRecorder) RemoveFile(file any) *gomock.Call

RemoveFile indicates an expected call of RemoveFile.

func (*MockReadWriterMockRecorder) SetRootdir

func (mr *MockReadWriterMockRecorder) SetRootdir(path any) *gomock.Call

SetRootdir indicates an expected call of SetRootdir.

func (*MockReadWriterMockRecorder) WriteFile

func (mr *MockReadWriterMockRecorder) WriteFile(name, data, perm any, opts ...any) *gomock.Call

WriteFile indicates an expected call of WriteFile.

type MockReader

type MockReader struct {
	// contains filtered or unexported fields
}

MockReader is a mock of Reader interface.

func NewMockReader

func NewMockReader(ctrl *gomock.Controller) *MockReader

NewMockReader creates a new mock instance.

func (*MockReader) EXPECT

func (m *MockReader) EXPECT() *MockReaderMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockReader) PathExists added in v0.4.0

func (m *MockReader) PathExists(path string, opts ...PathExistsOption) (bool, error)

PathExists mocks base method.

func (*MockReader) PathFor

func (m *MockReader) PathFor(filePath string) string

PathFor mocks base method.

func (*MockReader) ReadDir added in v0.3.0

func (m *MockReader) ReadDir(dirPath string) ([]fs.DirEntry, error)

ReadDir mocks base method.

func (*MockReader) ReadFile

func (m *MockReader) ReadFile(filePath string) ([]byte, error)

ReadFile mocks base method.

func (*MockReader) SetRootdir

func (m *MockReader) SetRootdir(path string)

SetRootdir mocks base method.

type MockReaderMockRecorder

type MockReaderMockRecorder struct {
	// contains filtered or unexported fields
}

MockReaderMockRecorder is the mock recorder for MockReader.

func (*MockReaderMockRecorder) PathExists added in v0.4.0

func (mr *MockReaderMockRecorder) PathExists(path any, opts ...any) *gomock.Call

PathExists indicates an expected call of PathExists.

func (*MockReaderMockRecorder) PathFor

func (mr *MockReaderMockRecorder) PathFor(filePath any) *gomock.Call

PathFor indicates an expected call of PathFor.

func (*MockReaderMockRecorder) ReadDir added in v0.3.0

func (mr *MockReaderMockRecorder) ReadDir(dirPath any) *gomock.Call

ReadDir indicates an expected call of ReadDir.

func (*MockReaderMockRecorder) ReadFile

func (mr *MockReaderMockRecorder) ReadFile(filePath any) *gomock.Call

ReadFile indicates an expected call of ReadFile.

func (*MockReaderMockRecorder) SetRootdir

func (mr *MockReaderMockRecorder) SetRootdir(path any) *gomock.Call

SetRootdir indicates an expected call of SetRootdir.

type MockWriter

type MockWriter struct {
	// contains filtered or unexported fields
}

MockWriter is a mock of Writer interface.

func NewMockWriter

func NewMockWriter(ctrl *gomock.Controller) *MockWriter

NewMockWriter creates a new mock instance.

func (*MockWriter) CopyFile

func (m *MockWriter) CopyFile(src, dst string) error

CopyFile mocks base method.

func (*MockWriter) CreateManagedFile

func (m *MockWriter) CreateManagedFile(file v1alpha1.FileSpec) (ManagedFile, error)

CreateManagedFile mocks base method.

func (*MockWriter) EXPECT

func (m *MockWriter) EXPECT() *MockWriterMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockWriter) MkdirAll added in v0.3.0

func (m *MockWriter) MkdirAll(path string, perm fs.FileMode) error

MkdirAll mocks base method.

func (*MockWriter) MkdirTemp added in v0.6.0

func (m *MockWriter) MkdirTemp(prefix string) (string, error)

MkdirTemp mocks base method.

func (*MockWriter) OverwriteAndWipe added in v0.4.0

func (m *MockWriter) OverwriteAndWipe(file string) error

OverwriteAndWipe mocks base method.

func (*MockWriter) PathFor added in v0.3.0

func (m *MockWriter) PathFor(filePath string) string

PathFor mocks base method.

func (*MockWriter) RemoveAll added in v0.3.0

func (m *MockWriter) RemoveAll(path string) error

RemoveAll mocks base method.

func (*MockWriter) RemoveContents added in v0.8.1

func (m *MockWriter) RemoveContents(path string) error

RemoveContents mocks base method.

func (*MockWriter) RemoveFile

func (m *MockWriter) RemoveFile(file string) error

RemoveFile mocks base method.

func (*MockWriter) SetRootdir

func (m *MockWriter) SetRootdir(path string)

SetRootdir mocks base method.

func (*MockWriter) WriteFile

func (m *MockWriter) WriteFile(name string, data []byte, perm fs.FileMode, opts ...FileOption) error

WriteFile mocks base method.

type MockWriterMockRecorder

type MockWriterMockRecorder struct {
	// contains filtered or unexported fields
}

MockWriterMockRecorder is the mock recorder for MockWriter.

func (*MockWriterMockRecorder) CopyFile

func (mr *MockWriterMockRecorder) CopyFile(src, dst any) *gomock.Call

CopyFile indicates an expected call of CopyFile.

func (*MockWriterMockRecorder) CreateManagedFile

func (mr *MockWriterMockRecorder) CreateManagedFile(file any) *gomock.Call

CreateManagedFile indicates an expected call of CreateManagedFile.

func (*MockWriterMockRecorder) MkdirAll added in v0.3.0

func (mr *MockWriterMockRecorder) MkdirAll(path, perm any) *gomock.Call

MkdirAll indicates an expected call of MkdirAll.

func (*MockWriterMockRecorder) MkdirTemp added in v0.6.0

func (mr *MockWriterMockRecorder) MkdirTemp(prefix any) *gomock.Call

MkdirTemp indicates an expected call of MkdirTemp.

func (*MockWriterMockRecorder) OverwriteAndWipe added in v0.4.0

func (mr *MockWriterMockRecorder) OverwriteAndWipe(file any) *gomock.Call

OverwriteAndWipe indicates an expected call of OverwriteAndWipe.

func (*MockWriterMockRecorder) PathFor added in v0.3.0

func (mr *MockWriterMockRecorder) PathFor(filePath any) *gomock.Call

PathFor indicates an expected call of PathFor.

func (*MockWriterMockRecorder) RemoveAll added in v0.3.0

func (mr *MockWriterMockRecorder) RemoveAll(path any) *gomock.Call

RemoveAll indicates an expected call of RemoveAll.

func (*MockWriterMockRecorder) RemoveContents added in v0.8.1

func (mr *MockWriterMockRecorder) RemoveContents(path any) *gomock.Call

RemoveContents indicates an expected call of RemoveContents.

func (*MockWriterMockRecorder) RemoveFile

func (mr *MockWriterMockRecorder) RemoveFile(file any) *gomock.Call

RemoveFile indicates an expected call of RemoveFile.

func (*MockWriterMockRecorder) SetRootdir

func (mr *MockWriterMockRecorder) SetRootdir(path any) *gomock.Call

SetRootdir indicates an expected call of SetRootdir.

func (*MockWriterMockRecorder) WriteFile

func (mr *MockWriterMockRecorder) WriteFile(name, data, perm any, opts ...any) *gomock.Call

WriteFile indicates an expected call of WriteFile.

type Option

type Option func(*readWriter)

func WithTestRootDir

func WithTestRootDir(testRootDir string) Option

WithTestRootDir sets the root directory for the reader and writer, useful for testing.

type PathExistsOption added in v0.9.0

type PathExistsOption func(*pathExistsOptions)

PathExistsOption represents options for PathExists function

func WithSkipContentCheck added in v0.9.0

func WithSkipContentCheck() PathExistsOption

WithSkipContentCheck configures PathExists to skip content verification and only check if the path can be opened

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

func NewReadWriter

func NewReadWriter(opts ...Option) ReadWriter

type Reader

type Reader interface {
	SetRootdir(path string)
	PathFor(filePath string) string
	ReadFile(filePath string) ([]byte, error)
	ReadDir(dirPath string) ([]fs.DirEntry, error)
	PathExists(path string, opts ...PathExistsOption) (bool, error)
}

type Writer

type Writer interface {
	// SetRootdir sets the root directory for the writer, useful for testing
	SetRootdir(path string)
	// PathFor returns the full path for the given filePath, prepending the rootDir if set
	// This is useful for testing to ensure that the file is written to the correct location
	PathFor(filePath string) string
	// WriteFile writes the provided data to the file at the path with the provided permissions and ownership information
	WriteFile(name string, data []byte, perm fs.FileMode, opts ...FileOption) error
	// RemoveFile removes the file at the given path
	RemoveFile(file string) error
	// RemoveAll removes the file or directory at the given path
	RemoveAll(path string) error
	// RemoveContents removes all files and subdirectories within the given path,
	// but leaves the directory itself intact. It is a no-op if the path does not exist.
	RemoveContents(path string) error
	// MkdirAll creates a directory at the given path with the specified permissions.
	MkdirAll(path string, perm fs.FileMode) error
	// MkdirTemp creates a temporary directory with the given prefix and returns its path.
	MkdirTemp(prefix string) (string, error)
	// CopyFile copies a file from src to dst, creating the destination directory if it does not exist.
	CopyFile(src, dst string) error
	// CreateManagedFile creates a managed file with the given spec.
	CreateManagedFile(file v1alpha1.FileSpec) (ManagedFile, error)
	// OverwriteAndWipe overwrites the file at the given path with zeros and then deletes it.
	OverwriteAndWipe(file string) error
}

Jump to

Keyboard shortcuts

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