filesystem

package
v0.0.0-...-0907127 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDir

func ReadDir(dirname string) ([]os.DirEntry, error)

func ReadFile

func ReadFile(filename string) ([]byte, error)

func Stat

func Stat(name string) (os.FileInfo, error)

Types

type FileSystemInterface

type FileSystemInterface interface {
	Stat(name string) (os.FileInfo, error)
	ReadDir(dirname string) ([]os.DirEntry, error)
	ReadFile(filename string) ([]byte, error)
}

FileSystemInterface defines the interface for filesystem operations to enable mocking. Modeled after linuxptp-daemon's addons/intel/common.go FileSystemInterface.

type MockDirEntry

type MockDirEntry struct {
	EntryName string
	Dir       bool
}

MockDirEntry implements os.DirEntry for testing

func (MockDirEntry) Info

func (m MockDirEntry) Info() (os.FileInfo, error)

func (MockDirEntry) IsDir

func (m MockDirEntry) IsDir() bool

func (MockDirEntry) Name

func (m MockDirEntry) Name() string

func (MockDirEntry) Type

func (m MockDirEntry) Type() os.FileMode

type MockFileSystem

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

MockFileSystem is a mock implementation of FileSystemInterface for testing. Modeled after linuxptp-daemon's addons/intel/mock_test.go MockFileSystem.

func SetupMockFS

func SetupMockFS() (*MockFileSystem, func())

SetupMockFS swaps the global filesystem implementation with a mock and returns a cleanup function.

func (*MockFileSystem) AllowReadDir

func (m *MockFileSystem) AllowReadDir(path string, dirs []os.DirEntry, err error)

func (*MockFileSystem) AllowReadFile

func (m *MockFileSystem) AllowReadFile(path string, data []byte, err error)

func (*MockFileSystem) AllowStat

func (m *MockFileSystem) AllowStat(path string, info os.FileInfo, err error)

func (*MockFileSystem) ExpectReadDir

func (m *MockFileSystem) ExpectReadDir(path string, dirs []os.DirEntry, err error)

func (*MockFileSystem) ExpectReadFile

func (m *MockFileSystem) ExpectReadFile(path string, data []byte, err error)

func (*MockFileSystem) ExpectStat

func (m *MockFileSystem) ExpectStat(path string, info os.FileInfo, err error)

func (*MockFileSystem) ReadDir

func (m *MockFileSystem) ReadDir(dirname string) ([]os.DirEntry, error)

func (*MockFileSystem) ReadFile

func (m *MockFileSystem) ReadFile(filename string) ([]byte, error)

func (*MockFileSystem) Stat

func (m *MockFileSystem) Stat(name string) (os.FileInfo, error)

func (*MockFileSystem) VerifyAllCalls

func (m *MockFileSystem) VerifyAllCalls(t *testing.T)

VerifyAllCalls asserts that all expected calls were made

type ReadDirCall

type ReadDirCall struct {
	ExpectedPath string
	ReturnDirs   []os.DirEntry
	ReturnError  error
}

ReadDirCall represents an expected or allowed ReadDir call

type ReadFileCall

type ReadFileCall struct {
	ExpectedPath string
	ReturnData   []byte
	ReturnError  error
}

ReadFileCall represents an expected or allowed ReadFile call

type RealFileSystem

type RealFileSystem struct{}

RealFileSystem implements FileSystemInterface using real OS operations

func (*RealFileSystem) ReadDir

func (fs *RealFileSystem) ReadDir(dirname string) ([]os.DirEntry, error)

func (*RealFileSystem) ReadFile

func (fs *RealFileSystem) ReadFile(filename string) ([]byte, error)

func (*RealFileSystem) Stat

func (fs *RealFileSystem) Stat(name string) (os.FileInfo, error)

type StatCall

type StatCall struct {
	ExpectedPath string
	ReturnInfo   os.FileInfo
	ReturnError  error
}

StatCall represents an expected or allowed Stat call

Jump to

Keyboard shortcuts

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