vfsmock

package
v0.0.0-...-5207eb8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSMock

type FSMock struct {
	// ChtimesFunc mocks the Chtimes method.
	ChtimesFunc func(path string, aTime time.Time, mTime time.Time) error

	// DirectoryExistsFunc mocks the DirectoryExists method.
	DirectoryExistsFunc func(path string) bool

	// FileExistsFunc mocks the FileExists method.
	FileExistsFunc func(path string) bool

	// GetAccessibleEntriesFunc mocks the GetAccessibleEntries method.
	GetAccessibleEntriesFunc func(path string) vfs.Entries

	// ReadFileFunc mocks the ReadFile method.
	ReadFileFunc func(path string) (string, bool)

	// RealpathFunc mocks the Realpath method.
	RealpathFunc func(path string) string

	// RemoveFunc mocks the Remove method.
	RemoveFunc func(path string) error

	// StatFunc mocks the Stat method.
	StatFunc func(path string) vfs.FileInfo

	// UseCaseSensitiveFileNamesFunc mocks the UseCaseSensitiveFileNames method.
	UseCaseSensitiveFileNamesFunc func() bool

	// WalkDirFunc mocks the WalkDir method.
	WalkDirFunc func(root string, walkFn vfs.WalkDirFunc) error

	// WriteFileFunc mocks the WriteFile method.
	WriteFileFunc func(path string, data string, writeByteOrderMark bool) error
	// contains filtered or unexported fields
}

FSMock is a mock implementation of vfs.FS.

func TestSomethingThatUsesFS(t *testing.T) {

	// make and configure a mocked vfs.FS
	mockedFS := &FSMock{
		ChtimesFunc: func(path string, aTime time.Time, mTime time.Time) error {
			panic("mock out the Chtimes method")
		},
		DirectoryExistsFunc: func(path string) bool {
			panic("mock out the DirectoryExists method")
		},
		FileExistsFunc: func(path string) bool {
			panic("mock out the FileExists method")
		},
		GetAccessibleEntriesFunc: func(path string) vfs.Entries {
			panic("mock out the GetAccessibleEntries method")
		},
		ReadFileFunc: func(path string) (string, bool) {
			panic("mock out the ReadFile method")
		},
		RealpathFunc: func(path string) string {
			panic("mock out the Realpath method")
		},
		RemoveFunc: func(path string) error {
			panic("mock out the Remove method")
		},
		StatFunc: func(path string) vfs.FileInfo {
			panic("mock out the Stat method")
		},
		UseCaseSensitiveFileNamesFunc: func() bool {
			panic("mock out the UseCaseSensitiveFileNames method")
		},
		WalkDirFunc: func(root string, walkFn vfs.WalkDirFunc) error {
			panic("mock out the WalkDir method")
		},
		WriteFileFunc: func(path string, data string, writeByteOrderMark bool) error {
			panic("mock out the WriteFile method")
		},
	}

	// use mockedFS in code that requires vfs.FS
	// and then make assertions.

}

func Wrap

func Wrap(fs vfs.FS) *FSMock

Wrap wraps a vfs.FS and returns a FSMock which calls it.

func (*FSMock) Chtimes

func (mock *FSMock) Chtimes(path string, aTime time.Time, mTime time.Time) error

Chtimes calls ChtimesFunc.

func (*FSMock) ChtimesCalls

func (mock *FSMock) ChtimesCalls() []struct {
	Path  string
	ATime time.Time
	MTime time.Time
}

ChtimesCalls gets all the calls that were made to Chtimes. Check the length with:

len(mockedFS.ChtimesCalls())

func (*FSMock) DirectoryExists

func (mock *FSMock) DirectoryExists(path string) bool

DirectoryExists calls DirectoryExistsFunc.

func (*FSMock) DirectoryExistsCalls

func (mock *FSMock) DirectoryExistsCalls() []struct {
	Path string
}

DirectoryExistsCalls gets all the calls that were made to DirectoryExists. Check the length with:

len(mockedFS.DirectoryExistsCalls())

func (*FSMock) FileExists

func (mock *FSMock) FileExists(path string) bool

FileExists calls FileExistsFunc.

func (*FSMock) FileExistsCalls

func (mock *FSMock) FileExistsCalls() []struct {
	Path string
}

FileExistsCalls gets all the calls that were made to FileExists. Check the length with:

len(mockedFS.FileExistsCalls())

func (*FSMock) GetAccessibleEntries

func (mock *FSMock) GetAccessibleEntries(path string) vfs.Entries

GetAccessibleEntries calls GetAccessibleEntriesFunc.

func (*FSMock) GetAccessibleEntriesCalls

func (mock *FSMock) GetAccessibleEntriesCalls() []struct {
	Path string
}

GetAccessibleEntriesCalls gets all the calls that were made to GetAccessibleEntries. Check the length with:

len(mockedFS.GetAccessibleEntriesCalls())

func (*FSMock) ReadFile

func (mock *FSMock) ReadFile(path string) (string, bool)

ReadFile calls ReadFileFunc.

func (*FSMock) ReadFileCalls

func (mock *FSMock) ReadFileCalls() []struct {
	Path string
}

ReadFileCalls gets all the calls that were made to ReadFile. Check the length with:

len(mockedFS.ReadFileCalls())

func (*FSMock) Realpath

func (mock *FSMock) Realpath(path string) string

Realpath calls RealpathFunc.

func (*FSMock) RealpathCalls

func (mock *FSMock) RealpathCalls() []struct {
	Path string
}

RealpathCalls gets all the calls that were made to Realpath. Check the length with:

len(mockedFS.RealpathCalls())

func (*FSMock) Remove

func (mock *FSMock) Remove(path string) error

Remove calls RemoveFunc.

func (*FSMock) RemoveCalls

func (mock *FSMock) RemoveCalls() []struct {
	Path string
}

RemoveCalls gets all the calls that were made to Remove. Check the length with:

len(mockedFS.RemoveCalls())

func (*FSMock) Stat

func (mock *FSMock) Stat(path string) vfs.FileInfo

Stat calls StatFunc.

func (*FSMock) StatCalls

func (mock *FSMock) StatCalls() []struct {
	Path string
}

StatCalls gets all the calls that were made to Stat. Check the length with:

len(mockedFS.StatCalls())

func (*FSMock) UseCaseSensitiveFileNames

func (mock *FSMock) UseCaseSensitiveFileNames() bool

UseCaseSensitiveFileNames calls UseCaseSensitiveFileNamesFunc.

func (*FSMock) UseCaseSensitiveFileNamesCalls

func (mock *FSMock) UseCaseSensitiveFileNamesCalls() []struct{}

UseCaseSensitiveFileNamesCalls gets all the calls that were made to UseCaseSensitiveFileNames. Check the length with:

len(mockedFS.UseCaseSensitiveFileNamesCalls())

func (*FSMock) WalkDir

func (mock *FSMock) WalkDir(root string, walkFn vfs.WalkDirFunc) error

WalkDir calls WalkDirFunc.

func (*FSMock) WalkDirCalls

func (mock *FSMock) WalkDirCalls() []struct {
	Root   string
	WalkFn vfs.WalkDirFunc
}

WalkDirCalls gets all the calls that were made to WalkDir. Check the length with:

len(mockedFS.WalkDirCalls())

func (*FSMock) WriteFile

func (mock *FSMock) WriteFile(path string, data string, writeByteOrderMark bool) error

WriteFile calls WriteFileFunc.

func (*FSMock) WriteFileCalls

func (mock *FSMock) WriteFileCalls() []struct {
	Path               string
	Data               string
	WriteByteOrderMark bool
}

WriteFileCalls gets all the calls that were made to WriteFile. Check the length with:

len(mockedFS.WriteFileCalls())

Jump to

Keyboard shortcuts

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