spi

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: EPL-2.0 Imports: 4 Imported by: 0

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

* 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

* 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

This section is empty.

Types

type Authenticator

type Authenticator interface {
	// Gets a bearer token from the persistent cache if there is one, else logs into the server to get one.
	GetBearerToken() (string, error)

	// Gets a new authenticated API client, attempting to log in if a bearer token file does not exist
	GetAuthenticatedAPIClient() (*galasaapi.APIClient, error)

	// Logs into the server, saving the JWT token obtained in a persistent cache for later
	Login() error

	LogoutOfEverywhere() error
}

type ByteReader added in v0.37.0

type ByteReader interface {
	ReadAll(reader io.Reader) ([]byte, error)
}

An interface to allow for mocking out "io" package reading-related methods

type Console

type Console interface {
	WriteString(text string) error
	Write(p []byte) (n int, err error)
}

------------------------------------------------- A console where things can be written to so the user can see them.

type Environment

type Environment interface {
	GetEnv(propertyName string) string
	GetUserName() (string, error)
}

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

type Factory

type Factory interface {
	GetFileSystem() FileSystem
	GetEnvironment() Environment
	GetFinalWordHandler() FinalWordHandler
	GetStdOutConsole() Console
	GetStdErrConsole() Console
	GetTimeService() TimeService
	GetAuthenticator(apiServerUrl string, galasaHome GalasaHome) Authenticator
	GetByteReader() ByteReader
}

We use the factory to create instances of various classes. Some are cached, so you get the same one back each time Some are fresh objects created each time. We do this so we can have a real and a mock implementation to make unit testing easier.

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

type FinalWordHandler

type FinalWordHandler interface {
	FinalWord(rootCmd GalasaCommand, errorToExctractFrom interface{})
}

A final word handler can set the exit code of the entire process. Or it could be mocked-out to just collect it and checked in tests.

type GalasaCommand

type GalasaCommand interface {
	// The name of the galasa command. One of the COMMAND_NAME_* constants.
	Name() string

	// Returns the cobra command which is part of the Galasa command.
	CobraCommand() *cobra.Command

	// Returns the data structure associated with this cobra command.
	Values() interface{}
}

A class which houses both the cobra command and the values structure the command puts things into.

type GalasaHome

type GalasaHome interface {
	GetNativeFolderPath() string
	GetUrlFolderPath() string
}

type TimeService

type TimeService interface {
	Now() time.Time
	Sleep(duration time.Duration)
}

type TimedSleeper added in v0.38.0

type TimedSleeper interface {
	Sleep(duration time.Duration)
	Interrupt(message string)
}

An encapsulation of code where one thread sleeps waiting for an event, but will timeout, and another thread interrupts the sleeper. This allows unit tests to simulate the interrupt easier in mock code without using separate threads.

Jump to

Keyboard shortcuts

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