filesystem

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package filesystem provides a filesystem interface and implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	Stat(name string) (fs.FileInfo, error)
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, data []byte, perm fs.FileMode) error
	Remove(name string) error
	Rename(oldpath, newpath string) error
	Open(name string) (io.ReadCloser, error)
	Exists(path string) (bool, error)
}

FileSystem defines the interface for filesystem operations used by the artifact manager.

type MockFileSystem

type MockFileSystem struct {
	Files     map[string][]byte
	StatErr   error
	ReadErr   error
	WriteErr  error
	RemoveErr error
	RenameErr error
	OpenErr   error

	WriteCalls  []writeCall
	RemoveCalls []string
	RenameCalls []renameCall
	// contains filtered or unexported fields
}

MockFileSystem implements FileSystem for testing.

func NewMockFileSystem

func NewMockFileSystem() *MockFileSystem

NewMockFileSystem creates a new mock filesystem.

func (*MockFileSystem) Exists

func (m *MockFileSystem) Exists(path string) (bool, error)

Exists checks if a file exists in the mock filesystem.

func (*MockFileSystem) Open

func (m *MockFileSystem) Open(name string) (io.ReadCloser, error)

Open opens the named file for reading and returns an io.ReadCloser.

func (*MockFileSystem) ReadFile

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

ReadFile reads and returns the contents of the named file.

func (*MockFileSystem) Remove

func (m *MockFileSystem) Remove(name string) error

Remove deletes the named file from the mock filesystem.

func (*MockFileSystem) Rename

func (m *MockFileSystem) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath in the mock filesystem.

func (*MockFileSystem) Stat

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

Stat returns file info for the named file, or an error if it does not exist.

func (*MockFileSystem) WriteFile

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

WriteFile writes data to the named file with the given permissions.

type OS

type OS struct{}

OS implements FileSystem using the real os package.

func NewOSFileSystem

func NewOSFileSystem() *OS

NewOSFileSystem creates a new OS filesystem.

func (OS) Exists

func (OS) Exists(path string) (bool, error)

Exists checks if the file exists.

func (OS) Open

func (OS) Open(name string) (io.ReadCloser, error)

Open opens the file at the given path.

func (OS) ReadFile

func (OS) ReadFile(name string) ([]byte, error)

ReadFile reads the file at the given path.

func (OS) Remove

func (OS) Remove(name string) error

Remove removes the file at the given path.

func (OS) Rename

func (OS) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath.

func (OS) Stat

func (OS) Stat(name string) (fs.FileInfo, error)

Stat returns file info for the given path.

func (OS) WriteFile

func (OS) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes data to the file at the given path.

Jump to

Keyboard shortcuts

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