files

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: EPL-2.0 Imports: 14 Imported by: 3

Documentation

Overview

* Copyright contributors to the Galasa project * * SPDX-License-Identifier: EPL-2.0

* Copyright contributors to the Galasa project * * SPDX-License-Identifier: EPL-2.0

* Copyright contributors to the Galasa project * * SPDX-License-Identifier: EPL-2.0

* Copyright contributors to the Galasa project * * SPDX-License-Identifier: EPL-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TildaExpansion

func TildaExpansion(fileSystem FileSystem, path string) (string, error)

TildaExpansion If a file starts with a tilda '~' character, expand it to the home folder of the user on this file system.

Types

type FileSystem

type FileSystem interface {
	// MkdirAll creates all folders in the file system if they don't already exist.
	MkdirAll(targetFolderPath string) error
	ReadTextFile(filePath string) (string, error)
	ReadBinaryFile(filePath string) ([]byte, error)
	WriteTextFile(targetFilePath string, desiredContents string) error
	WriteBinaryFile(targetFilePath string, desiredContents []byte) error
	Exists(path string) (bool, error)
	DirExists(path string) (bool, error)
	GetUserHomeDirPath() (string, error)
	OutputWarningMessage(string) error
	MkTempDir() (string, error)
	DeleteDir(path string)
	DeleteFile(path string)

	// Creates a file in the file system if it can.
	Create(path string) (io.WriteCloser, error)

	// Returns the normal extension used for executable files.
	// ie: The .exe suffix in windows, or "" in unix-like systems.
	GetExecutableExtension() string

	// GetPathSeparator returns the file path separator specific
	// to this operating system.
	GetFilePathSeparator() string

	// Gets all the file paths recursively from a starting folder.
	GetAllFilePaths(rootPath string) ([]string, error)
}

FileSystem is a thin interface layer above the os package which can be mocked out

func NewMockFileSystem

func NewMockFileSystem() FileSystem

NewMockFileSystem creates an implementation of the thin file system layer which delegates to a memory map. This uses the default behaviour for all the virtual functions in our MockFileSystem

func NewOSFileSystem

func NewOSFileSystem() FileSystem

NewOSFileSystem creates an implementation of the thin file system layer which delegates to the real os package calls.

type GzipFile added in v0.32.0

type GzipFile interface {
	ReadBytes() ([]byte, error)
	WriteBytes(binaryContent []byte) error
}

func NewGzipFile added in v0.32.0

func NewGzipFile(fs FileSystem, pathToGzip string) GzipFile

type GzipImpl added in v0.32.0

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

For gzip files, we need a utility which reads and writes gzip files to a file system.

func (*GzipImpl) ReadBytes added in v0.32.0

func (gzipFile *GzipImpl) ReadBytes() ([]byte, error)

func (*GzipImpl) WriteBytes added in v0.32.0

func (gzipFile *GzipImpl) WriteBytes(binaryContent []byte) error

type MockFile

type MockFile struct {

	// The mock struct contains methods which can be over-ridden on a per-test basis.
	VirtualFunction_Write func(contents []byte) (int, error)
	VirtualFunction_Close func() error
	// contains filtered or unexported fields
}

------------------------------------------------------------------------------------ The implementation of the io.writer interface. -----------------------------------------------------------------------------------

func NewOverridableMockFile

func NewOverridableMockFile(fs *MockFileSystem, filePath string) *MockFile

Creates an implementation of a mock file and allows callers to set up different virtual functions to change the mock behaviours.

func (*MockFile) Close added in v0.32.0

func (mockFile *MockFile) Close() error

func (*MockFile) Write

func (mockFile *MockFile) Write(contents []byte) (int, error)

type MockFileSystem

type MockFileSystem struct {

	// The mock struct contains methods which can be over-ridden on a per-test basis.
	// The New
	VirtualFunction_MkdirAll             func(targetFolderPath string) error
	VirtualFunction_WriteTextFile        func(targetFilePath string, desiredContents string) error
	VirtualFunction_ReadBinaryFile       func(filePath string) ([]byte, error)
	VirtualFunction_ReadTextFile         func(filePath string) (string, error)
	VirtualFunction_Exists               func(path string) (bool, error)
	VirtualFunction_DirExists            func(path string) (bool, error)
	VirtualFunction_GetUserHomeDirPath   func() (string, error)
	VirtualFunction_WriteBinaryFile      func(targetFilePath string, desiredContents []byte) error
	VirtualFunction_OutputWarningMessage func(string) error
	VirtualFunction_MkTempDir            func() (string, error)
	VirtualFunction_DeleteDir            func(path string)
	VirtualFunction_DeleteFile           func(path string)
	VirtualFunction_Create               func(path string) (io.WriteCloser, error)
	// contains filtered or unexported fields
}

func NewOverridableMockFileSystem

func NewOverridableMockFileSystem() *MockFileSystem

NewOverridableMockFileSystem creates an implementation of the thin file system layer which delegates to delegates to a memory map, but because the MockFileSystem is returned (rather than a FileSystem) it means the caller can set up different virtual functions, to change the behaviour.

func (*MockFileSystem) Create

func (fs *MockFileSystem) Create(path string) (io.WriteCloser, error)

func (*MockFileSystem) DeleteDir

func (fs *MockFileSystem) DeleteDir(pathToDelete string)

func (*MockFileSystem) DeleteFile

func (fs *MockFileSystem) DeleteFile(pathToDelete string)

func (*MockFileSystem) DirExists

func (fs *MockFileSystem) DirExists(path string) (bool, error)

func (*MockFileSystem) Exists

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

func (*MockFileSystem) GetAllFilePaths added in v0.32.0

func (fs *MockFileSystem) GetAllFilePaths(rootPath string) ([]string, error)

func (MockFileSystem) GetAllWarningMessages

func (fs MockFileSystem) GetAllWarningMessages() string

func (*MockFileSystem) GetExecutableExtension

func (fs *MockFileSystem) GetExecutableExtension() string

func (*MockFileSystem) GetFilePathSeparator

func (fs *MockFileSystem) GetFilePathSeparator() string

func (*MockFileSystem) GetUserHomeDirPath

func (fs *MockFileSystem) GetUserHomeDirPath() (string, error)

func (*MockFileSystem) MkTempDir

func (fs *MockFileSystem) MkTempDir() (string, error)

func (*MockFileSystem) MkdirAll

func (fs *MockFileSystem) MkdirAll(targetFolderPath string) error

func (MockFileSystem) OutputWarningMessage

func (fs MockFileSystem) OutputWarningMessage(message string) error

func (*MockFileSystem) ReadBinaryFile added in v0.32.0

func (fs *MockFileSystem) ReadBinaryFile(filePath string) ([]byte, error)

func (*MockFileSystem) ReadTextFile

func (fs *MockFileSystem) ReadTextFile(filePath string) (string, error)

func (*MockFileSystem) SetExecutableExtension

func (fs *MockFileSystem) SetExecutableExtension(newExtension string)

func (*MockFileSystem) SetFilePathSeparator

func (fs *MockFileSystem) SetFilePathSeparator(newSeparator string)

func (*MockFileSystem) WriteBinaryFile

func (fs *MockFileSystem) WriteBinaryFile(targetFilePath string, desiredContents []byte) error

func (*MockFileSystem) WriteTextFile

func (fs *MockFileSystem) WriteTextFile(targetFilePath string, desiredContents string) error

WriteTextFile writes a string to a text file

type Node

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

------------------------------------------------------------------------------------ The implementation of the file system interface built on an in-memory map. ------------------------------------------------------------------------------------

type OSFileSystem

type OSFileSystem struct {
}

func (*OSFileSystem) Create

func (osFS *OSFileSystem) Create(path string) (io.WriteCloser, error)

func (*OSFileSystem) DeleteDir

func (osFS *OSFileSystem) DeleteDir(path string)

func (*OSFileSystem) DeleteFile

func (osFS *OSFileSystem) DeleteFile(path string)

func (*OSFileSystem) DirExists

func (*OSFileSystem) DirExists(path string) (bool, error)

func (*OSFileSystem) Exists

func (*OSFileSystem) Exists(path string) (bool, error)

func (*OSFileSystem) GetAllFilePaths added in v0.32.0

func (osFS *OSFileSystem) GetAllFilePaths(rootPath string) ([]string, error)

func (*OSFileSystem) GetExecutableExtension

func (osFS *OSFileSystem) GetExecutableExtension() string

func (*OSFileSystem) GetFilePathSeparator

func (osFS *OSFileSystem) GetFilePathSeparator() string

func (*OSFileSystem) GetUserHomeDirPath

func (*OSFileSystem) GetUserHomeDirPath() (string, error)

func (*OSFileSystem) MkTempDir

func (osFS *OSFileSystem) MkTempDir() (string, error)

func (*OSFileSystem) MkdirAll

func (osFS *OSFileSystem) MkdirAll(targetFolderPath string) error

func (OSFileSystem) OutputWarningMessage

func (OSFileSystem) OutputWarningMessage(message string) error

func (*OSFileSystem) ReadBinaryFile added in v0.32.0

func (*OSFileSystem) ReadBinaryFile(filePath string) ([]byte, error)

func (*OSFileSystem) ReadTextFile

func (osFS *OSFileSystem) ReadTextFile(filePath string) (string, error)

func (*OSFileSystem) WriteBinaryFile

func (osFS *OSFileSystem) WriteBinaryFile(targetFilePath string, desiredContents []byte) error

func (*OSFileSystem) WriteTextFile

func (osFS *OSFileSystem) WriteTextFile(targetFilePath string, desiredContents string) error

Jump to

Keyboard shortcuts

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