filesystem

package
v0.0.0-...-8bfff4f Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package filesystem is used for providing OS level file utility methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	MkdirAll(string, os.FileMode) error
	ReadFile(string) ([]byte, error)
	ReadDir(string) ([]fs.FileInfo, error)
	Open(string) (*os.File, error)
	OpenFile(string, int, os.FileMode) (*os.File, error)
	RemoveAll(string) error
	Create(string) (*os.File, error)
	WriteStringToFile(*os.File, string) (int, error)
	Rename(string, string) error
	Copy(io.Writer, io.Reader) (int64, error)
	Chmod(string, os.FileMode) error
	Stat(string) (os.FileInfo, error)
	WalkAndZip(string, zipper.Zipper, *zip.Writer) error
	Seek(*os.File, int64, int) (int64, error)
}

FileSystem interface is an interface created to help make OS file system methods testable. Any caller should be able to provide their own mocked implementation in the unit tests.

type Helper

type Helper struct{}

Helper provides a real implementation of the FileSystem interface

func (Helper) Chmod

func (h Helper) Chmod(path string, perm os.FileMode) error

Chmod provides testable implementation of os.Chmod method.

func (Helper) Copy

func (h Helper) Copy(w io.Writer, r io.Reader) (int64, error)

Copy provides testable implementation of io.Copy method.

func (Helper) Create

func (h Helper) Create(path string) (*os.File, error)

Create provides testable implementation of os.Create method.

func (Helper) MkdirAll

func (h Helper) MkdirAll(path string, perm os.FileMode) error

MkdirAll provides testable implementation of os.MkdirAll method

func (Helper) Open

func (h Helper) Open(path string) (*os.File, error)

Open provides testable implementation of os.Open method.

func (Helper) OpenFile

func (h Helper) OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

OpenFile provides testable implementation of os.OpenFile method.

func (Helper) ReadDir

func (h Helper) ReadDir(path string) ([]fs.FileInfo, error)

ReadDir provides testable implementation of os.ReadDir method.

func (Helper) ReadFile

func (h Helper) ReadFile(path string) ([]byte, error)

ReadFile provides testable implementation of os.ReadFile method.

func (Helper) RemoveAll

func (h Helper) RemoveAll(path string) error

RemoveAll provides testable implementation of os.RemoveAll method.

func (Helper) Rename

func (h Helper) Rename(old, new string) error

Rename provides testable implementation of os.Rename method.

func (Helper) Seek

func (h Helper) Seek(file *os.File, offset int64, whence int) (int64, error)

Seek provides testable implementation of os.Seek method.

func (Helper) Stat

func (h Helper) Stat(path string) (os.FileInfo, error)

Stat provides testable implementation of os.Stat method.

func (Helper) WalkAndZip

func (h Helper) WalkAndZip(source string, z zipper.Zipper, w *zip.Writer) error

WalkAndZip provides testable implementation of filepath.Walk which zips the content of the directory.

func (Helper) WriteStringToFile

func (h Helper) WriteStringToFile(file *os.File, content string) (int, error)

WriteStringToFile provides testable implementation of os.WriteStringToFile method.

Directories

Path Synopsis
Package fake provides a fake implementation of the filesystem interface for unit tests
Package fake provides a fake implementation of the filesystem interface for unit tests

Jump to

Keyboard shortcuts

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