Documentation ¶
Overview ¶
Copyright (c) 2021 - for information on the respective copyright owner see the NOTICE file and/or the repository https://github.com/carbynestack/ephemeral.
SPDX-License-Identifier: Apache-2.0
Index ¶
- func ReadFile(path string) ([]byte, error)
- type Commander
- type CreatePathResponse
- type CreatePipeResponse
- type DeleteResponse
- type Executor
- type File
- type FileErrorPair
- type FileIO
- type MockedBrokenRoundTripper
- type MockedFileIO
- func (mfio *MockedFileIO) CreatePath(path string) error
- func (mfio *MockedFileIO) CreatePipe(path string) error
- func (mfio *MockedFileIO) Delete(path string) error
- func (mfio *MockedFileIO) OpenRead(path string) (File, error)
- func (mfio *MockedFileIO) OpenWriteOrCreate(path string) (File, error)
- func (mfio *MockedFileIO) OpenWritePipe(path string) (File, error)
- func (mfio *MockedFileIO) ReadLine(file File) (string, error)
- type MockedRoundTripper
- type OSFileIO
- func (OSFileIO) CreatePath(path string) error
- func (OSFileIO) CreatePipe(path string) error
- func (OSFileIO) Delete(path string) error
- func (OSFileIO) OpenRead(path string) (File, error)
- func (OSFileIO) OpenWriteOrCreate(path string) (File, error)
- func (OSFileIO) OpenWritePipe(path string) (File, error)
- func (OSFileIO) ReadLine(file File) (string, error)
- type OpenReadResponse
- type OpenWriteOrCreateResponse
- type OpenWritePipeResponse
- type ReadLineResponse
- type SimpleFileMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Commander ¶
Commander is a wrapper around os/exec.Command(). It returns a byte array containing the output of stdout and error. An error in command execution will land there. Stderr is scanned as well, its output is printed out.
func (*Commander) CallCMD ¶
CallCMD calls a specified command in sh and returns its stdout and stderr as a byte slice and potentially an error. As per os/exec doc: ``` If the command fails to run or doesn't complete successfully, the error is of type *ExitError. Other error types may be returned for I/O problems. ```
type CreatePathResponse ¶
type CreatePathResponse error
CreatePathResponse is used to define the default response returned by MockedFileIO.CreatePath calls.
type CreatePipeResponse ¶
type CreatePipeResponse error
CreatePipeResponse is used to define the default response returned by MockedFileIO.CreatePipe calls.
type DeleteResponse ¶
type DeleteResponse error
DeleteResponse is used to define the default response returned by MockedFileIO.Delete calls.
type Executor ¶
type Executor interface { // CallCMD executes the command and returns the output's STDOUT, STDERR streams as well as any errors CallCMD(ctx context.Context, cmd []string, dir string) ([]byte, []byte, error) }
Executor is an interface for calling a command and process its output.
type File ¶
type File interface { io.ReadWriteCloser io.StringWriter SetWriteDeadline(t time.Time) error }
File is an interface for basic file based io methods
type FileErrorPair ¶
FileErrorPair is a tuple of File and error as returned by some MockedFileIO methods.
type FileIO ¶
type FileIO interface { CreatePath(path string) error CreatePipe(path string) error Delete(path string) error OpenRead(path string) (File, error) OpenWriteOrCreate(name string) (File, error) OpenWritePipe(name string) (File, error) ReadLine(file File) (string, error) }
FileIO is an interface for filesystem methods
type MockedBrokenRoundTripper ¶
type MockedBrokenRoundTripper struct { }
MockedBrokenRoundTripper mocks http.RoundTripper for testing which will always result in an error
type MockedFileIO ¶
type MockedFileIO struct { CreatePathResponse CreatePathResponse CreatePathCalls []string CreatePipeResponse CreatePipeResponse CreatePipeCalls []string DeleteResponse DeleteResponse DeleteCalls []string OpenReadResponse OpenReadResponse OpenReadCalls []string OpenWriteOrCreateResponse OpenWriteOrCreateResponse OpenWriteOrCreateCalls []string OpenWritePipeResponse OpenWritePipeResponse OpenWritePipeCalls []string ReadLineResponse ReadLineResponse ReadLineCalls []File }
MockedFileIO implements fileIO as a mock for testing
func (*MockedFileIO) CreatePath ¶
func (mfio *MockedFileIO) CreatePath(path string) error
CreatePath mocks the creation of a directory. Returns MockedFileIO.CreatePathResponse.
func (*MockedFileIO) CreatePipe ¶
func (mfio *MockedFileIO) CreatePipe(path string) error
CreatePipe mocks the creation of a named pipe. Returns MockedFileIO.CreatePipeResponse.
func (*MockedFileIO) Delete ¶
func (mfio *MockedFileIO) Delete(path string) error
Delete mocks the deletion of a file. Returns MockedFileIO.DeleteResponse.
func (*MockedFileIO) OpenRead ¶
func (mfio *MockedFileIO) OpenRead(path string) (File, error)
OpenRead mocks opening a file for reading. Returns the attributes from MockedFileIO.OpenReadResponse.
func (*MockedFileIO) OpenWriteOrCreate ¶
func (mfio *MockedFileIO) OpenWriteOrCreate(path string) (File, error)
OpenWriteOrCreate mocks opening a file for write access. Returns the attributes from MockedFileIO.OpenWriteOrCreateResponse.
func (*MockedFileIO) OpenWritePipe ¶
func (mfio *MockedFileIO) OpenWritePipe(path string) (File, error)
OpenWritePipe mocks opening a named pipe for write access. Returns the attributes from MockedFileIO.OpenWritePipeResponse.
type MockedRoundTripper ¶
MockedRoundTripper mocks http.RoundTripper for testing which always returns successful
type OSFileIO ¶
type OSFileIO struct{}
OSFileIO implements fileIO backed by default os methods
func (OSFileIO) CreatePath ¶
CreatePath creates a directory and all parents if required. Returns nil on success or an error otherwise. This implementation is backed by os.MkdirAll.
func (OSFileIO) CreatePipe ¶
CreatePipe creates a named pipe. Returns nil on success or an error otherwise. This implementation is backed by unix.Mkfifo.
func (OSFileIO) Delete ¶
Delete deletes a single file or directory with all contained elements. Returns nil on success or an error otherwise. This implementation is backed by os.Remove.
func (OSFileIO) OpenRead ¶
OpenRead opens a file for reading. Returns a file which can be accessed for further processing. If opening the file fails, an error is returned instead. This implementation is backed by os.Open.
func (OSFileIO) OpenWriteOrCreate ¶
OpenWriteOrCreate opens a file for write access. The given file is created in case it does not exist. On success, a file is returned for further interaction. Otherwise, an error is returned. This implementation is backed by os.OpenFile.
func (OSFileIO) OpenWritePipe ¶
OpenWritePipe opens a named pipe for write access. Returns a file which can be accessed for further processing. Otherwise, an error is returned. This implementation is backed by os.OpenFile.
type OpenReadResponse ¶
type OpenReadResponse FileErrorPair
OpenReadResponse is used to define the default response returned by MockedFileIO.OpenRead calls.
type OpenWriteOrCreateResponse ¶
type OpenWriteOrCreateResponse FileErrorPair
OpenWriteOrCreateResponse is used to define the default response returned by MockedFileIO.OpenWriteOrCreate calls.
type OpenWritePipeResponse ¶
type OpenWritePipeResponse FileErrorPair
OpenWritePipeResponse is used to define the default response returned by MockedFileIO.OpenWritePipe calls.
type ReadLineResponse ¶
ReadLineResponse is a tuple of a string and an error as returned by MockedFileIO.ReadLine.
type SimpleFileMock ¶
type SimpleFileMock struct { ReadWriteCountResponse int IOError error SetDeadlineError error CloseError error WrittenData []byte WriteDeadline time.Time }
SimpleFileMock mocks os.File i/o for testing.
The error given in IOError is returned on all methods. Data written is appended to IOData on with each call an the length of the passed data returned as number of bytes written.
func (*SimpleFileMock) Close ¶
func (sfm *SimpleFileMock) Close() error
Close mocks the close call and returns defined CloseError
func (*SimpleFileMock) Read ¶
func (sfm *SimpleFileMock) Read(t []byte) (int, error)
Read mocks read calls. Data stored in WrittenData is copied to the given target array 't' at max of length of 't'. Returns length of copied data and IOError.
func (*SimpleFileMock) SetWriteDeadline ¶
func (sfm *SimpleFileMock) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets WriteDeadline
func (*SimpleFileMock) Write ¶
func (sfm *SimpleFileMock) Write(d []byte) (int, error)
Write mocks the function Write call, appends given data to WriteData and returns defined CloseError.
func (*SimpleFileMock) WriteString ¶
func (sfm *SimpleFileMock) WriteString(d string) (int, error)
WriteString mocks the WriteString call, appends given data to WriteData and returns defined CloseError.