utils

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: EPL-2.0 Imports: 26 Imported by: 2

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

* 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

* 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

View Source
const (
	LOWER_CASE_LETTERS = "abcdefghijklmnopqrstuvwxyz"
	DIGITS             = "0123456789"
	SEPARATOR          = "."
)
View Source
const (
	MAVEN_REPO_URL_GALASA_BLEEDING_EDGE = "https://development.galasa.dev/main/maven-repo/obr"
	MAVEN_REPO_URL_MAVEN_CENTRAL        = "https://repo.maven.apache.org/maven2"
)
View Source
const (
	SECONDS_BETWEEN_INTERRUPTED_CHECKS  = 3
	DURATION_BETWEEN_INTERRUPTED_CHECKS = SECONDS_BETWEEN_INTERRUPTED_CHECKS * time.Second
)
View Source
const (
	// The maximum value we can cope with for the encryption.
	// We hold all the data in memory so need to be defensive we don't try to encrypt too much.
	MAX_TEXT_TO_ENCRYPT = 2048
)

Variables

This section is empty.

Functions

func AddJavaRuntimeToMock

func AddJavaRuntimeToMock(fileSystem spi.FileSystem, baseJavaFolderName string)

func CaptureLog

func CaptureLog(fileSystem spi.FileSystem, logFileName string) error

* CaptureLog(logFileName) decides whether to re-direct the log information to the * specified file, or if the file name is "-" or empty, the log information won't be * re-directed, but will appear on stderr.

func Decrypt added in v0.34.0

func Decrypt(secret string, encryptedText string) (string, error)

func DeleteAllBearerTokenFiles added in v0.34.0

func DeleteAllBearerTokenFiles(fileSystem spi.FileSystem, galasaHome spi.GalasaHome) error

func Encrypt added in v0.34.0

func Encrypt(secret string, textToEncrypt string) (string, error)

func GetGalasaBootJarPath

func GetGalasaBootJarPath(fs spi.FileSystem, home spi.GalasaHome) (string, error)

func InitialiseGalasaHomeFolder

func InitialiseGalasaHomeFolder(home spi.GalasaHome, fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem) error

func InitialiseM2Folder

func InitialiseM2Folder(fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem, isDevelopment bool) error

func ListAllBearerTokenFiles added in v0.34.0

func ListAllBearerTokenFiles(fileSystem spi.FileSystem, galasaHome spi.GalasaHome) ([]string, error)

func NewByteReader added in v0.37.0

func NewByteReader() spi.ByteReader

func NewEnvironment

func NewEnvironment() spi.Environment

func NewGalasaHome

func NewGalasaHome(fs spi.FileSystem, env spi.Environment, cmdFlagGalasaHome string) (spi.GalasaHome, error)

func NewMockAuthenticator added in v0.34.0

func NewMockAuthenticator() spi.Authenticator

func NewMockByteReader added in v0.37.0

func NewMockByteReader() spi.ByteReader

func NewMockFinalWordHandler added in v0.34.0

func NewMockFinalWordHandler() spi.FinalWordHandler

func NewMockTimeService

func NewMockTimeService() spi.TimeService

func NewOverridableMockTimeService

func NewOverridableMockTimeService(now time.Time) spi.TimeService

func NewRealTimeService

func NewRealTimeService() spi.TimeService

func UppercaseFirstLetter

func UppercaseFirstLetter(s string) string

UppercaseFirstLetter - takes a string and returns the same string, but with the first letter turned into an uppercase letter.

func ValidateJavaHome

func ValidateJavaHome(fileSystem spi.FileSystem, javaHome string) error

validateJavaHome validate that JAVA_HOME is set correctly. If $JAVA_HOME ends with a '/' (or '\' for windows, the trailing slash is removed before checks are made.

Constraints: - It must be set. - JAVA_HOME/bin must be a folder which exists. - JAVA_HOME/bin/java must exist as a file.

func ValidateJavaPackageName

func ValidateJavaPackageName(javaPackageName string) error

To validate the string as a valid java package name before we start to use it.

Types

type BearerTokenFile added in v0.34.0

type BearerTokenFile interface {
	WriteJwt(jwt string, encryptionSecret string) error
	ReadJwt(encryptionSecret string) (string, error)
	DeleteJwt() error
	Exists() (bool, error)
}

func NewBearerTokenFile added in v0.34.0

func NewBearerTokenFile(
	fileSystem spi.FileSystem,
	galasaHome spi.GalasaHome,
	baseFileName string,
	timeService spi.TimeService,
) BearerTokenFile

type BearerTokenFileImpl added in v0.34.0

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

func (*BearerTokenFileImpl) DeleteJwt added in v0.34.0

func (file *BearerTokenFileImpl) DeleteJwt() error

func (*BearerTokenFileImpl) Exists added in v0.34.0

func (file *BearerTokenFileImpl) Exists() (bool, error)

func (*BearerTokenFileImpl) ReadJwt added in v0.34.0

func (file *BearerTokenFileImpl) ReadJwt(encryptionSecret string) (string, error)

Gets the JWT from the bearer-token.json file if it exists, errors if the file does not exist or if the token is invalid

func (*BearerTokenFileImpl) WriteJwt added in v0.34.0

func (file *BearerTokenFileImpl) WriteJwt(jwt string, encryptionSecret string) error

Writes a new bearer-token.json file containing a JWT in the following format:

{
  "jwt": "<bearer-token-here>"
}

type BearerTokenJson added in v0.33.0

type BearerTokenJson struct {
	Jwt string `json:"jwt"`
}

type BlankTemplateParameters

type BlankTemplateParameters struct{}

type ByteReaderImpl added in v0.37.0

type ByteReaderImpl struct {
}

Implementation of a byte reader to allow mocking out methods from the io package

func (*ByteReaderImpl) ReadAll added in v0.37.0

func (*ByteReaderImpl) ReadAll(reader io.Reader) ([]byte, error)

type FileGenerator

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

func NewFileGenerator

func NewFileGenerator(fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem) *FileGenerator

func (*FileGenerator) CreateFile

func (generator *FileGenerator) CreateFile(
	generatedFile GeneratedFileDef,
	forceOverwrite bool,
	isExistsAnError bool) error

createFile creates a file on the file system. If forceOverwrite is false, and there is already a file there, then an error will occur.

func (*FileGenerator) CreateFolder

func (generator *FileGenerator) CreateFolder(targetFolderPath string) error

type GeneratedFileDef

type GeneratedFileDef struct {
	FileType                 string
	TargetFilePath           string
	EmbeddedTemplateFilePath string
	TemplateParameters       interface{}
}

type HttpInteraction added in v0.37.0

type HttpInteraction struct {
	ExpectedPath       string
	ExpectedHttpMethod string

	// An override-able function to write a HTTP response for this interaction
	WriteHttpResponseFunc func(writer http.ResponseWriter, req *http.Request)
}

The implementation of a HTTP interaction that allows unit tests to define interactions with the Galasa API server, with methods to validate requests and a lambda to write HTTP responses (which can be overridden as desired)

func NewHttpInteraction added in v0.37.0

func NewHttpInteraction(expectedPath string, expectedHttpMethod string) HttpInteraction

func (*HttpInteraction) ValidateRequest added in v0.37.0

func (interaction *HttpInteraction) ValidateRequest(t *testing.T, req *http.Request)

type JavaClassDef

type JavaClassDef struct {
	PackageName string
	ClassName   string
}

type MavenCoordinates

type MavenCoordinates struct {
	GroupId    string
	ArtifactId string
	Version    string
	Classifier string
}

func ValidateObr

func ValidateObr(obr string) (MavenCoordinates, error)

We expect a parameter to be of the form: mvn:dev.galasa.example.banking/dev.galasa.example.banking.obr/0.0.1-SNAPSHOT/obr Validate that the --obr parameter or portfolio field passed by the user conform to this convention by splitting the input into pieces.

func ValidateObrs

func ValidateObrs(obrInputs []string) ([]MavenCoordinates, error)

We expect a parameter to be of the form: mvn:dev.galasa.example.banking/dev.galasa.example.banking.obr/0.0.1-SNAPSHOT/obr Validate that the --obr parameter or portfolio field passed by the user conform to this convention by splitting the input into pieces.

type MockAuthenticator added in v0.34.0

type MockAuthenticator struct {
}

func (*MockAuthenticator) GetAuthenticatedAPIClient added in v0.34.0

func (authenticator *MockAuthenticator) GetAuthenticatedAPIClient() (*galasaapi.APIClient, error)

Gets a new authenticated API client, attempting to log in if a bearer token file does not exist

func (*MockAuthenticator) GetBearerToken added in v0.34.0

func (authenticator *MockAuthenticator) GetBearerToken() (string, error)

func (*MockAuthenticator) Login added in v0.34.0

func (authenticator *MockAuthenticator) Login() error

Login - performs all the logic to implement the `galasactl auth login` command

func (*MockAuthenticator) LogoutOfEverywhere added in v0.34.0

func (authenticator *MockAuthenticator) LogoutOfEverywhere() error

Login - performs all the logic to implement the `galasactl auth login` command

type MockByteReader added in v0.37.0

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

Mock implementation of a byte reader to allow for simulating failed read operations

func NewMockByteReaderAsMock added in v0.37.0

func NewMockByteReaderAsMock(throwReadError bool) *MockByteReader

func (*MockByteReader) ReadAll added in v0.37.0

func (mockReader *MockByteReader) ReadAll(reader io.Reader) ([]byte, error)

type MockConsole

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

------------------------------------------------- A mock implementation which writes text to a buffer Useful for unit testing.

func NewMockConsole

func NewMockConsole() *MockConsole

func (*MockConsole) ReadText

func (data *MockConsole) ReadText() string

func (*MockConsole) Write

func (data *MockConsole) Write(p []byte) (n int, err error)

func (*MockConsole) WriteString

func (this *MockConsole) WriteString(text string) error

type MockEnv

type MockEnv struct {
	EnvVars map[string]string
	// contains filtered or unexported fields
}

func NewMockEnv

func NewMockEnv() *MockEnv

func (*MockEnv) GetEnv

func (env *MockEnv) GetEnv(propertyName string) string

func (*MockEnv) GetUserName

func (env *MockEnv) GetUserName() (string, error)

func (*MockEnv) SetEnv

func (env *MockEnv) SetEnv(propertyName string, value string)

func (*MockEnv) SetUserName

func (env *MockEnv) SetUserName(name string)

type MockFactory added in v0.34.0

type MockFactory struct {
	FinalWordHandler spi.FinalWordHandler
	FileSystem       spi.FileSystem
	Env              spi.Environment
	StdOutConsole    spi.Console
	StdErrConsole    spi.Console
	TimeService      spi.TimeService
	Authenticator    spi.Authenticator
	ByteReader       spi.ByteReader
}

func NewMockFactory added in v0.34.0

func NewMockFactory() *MockFactory

func (*MockFactory) GetAuthenticator added in v0.34.0

func (factory *MockFactory) GetAuthenticator(apiServerUrl string, galasaHome spi.GalasaHome) spi.Authenticator

func (*MockFactory) GetByteReader added in v0.37.0

func (factory *MockFactory) GetByteReader() spi.ByteReader

func (*MockFactory) GetEnvironment added in v0.34.0

func (factory *MockFactory) GetEnvironment() spi.Environment

func (*MockFactory) GetFileSystem added in v0.34.0

func (factory *MockFactory) GetFileSystem() spi.FileSystem

func (*MockFactory) GetFinalWordHandler added in v0.34.0

func (factory *MockFactory) GetFinalWordHandler() spi.FinalWordHandler

func (*MockFactory) GetStdErrConsole added in v0.34.0

func (factory *MockFactory) GetStdErrConsole() spi.Console

func (*MockFactory) GetStdOutConsole added in v0.34.0

func (factory *MockFactory) GetStdOutConsole() spi.Console

func (*MockFactory) GetTimeService added in v0.34.0

func (factory *MockFactory) GetTimeService() spi.TimeService

type MockFinalWordHandler added in v0.34.0

type MockFinalWordHandler struct {
	ReportedObject interface{}
}

func (*MockFinalWordHandler) FinalWord added in v0.34.0

func (handler *MockFinalWordHandler) FinalWord(rootCmd spi.GalasaCommand, errorToExctractFrom interface{})

type MockHttpServer added in v0.37.0

type MockHttpServer struct {
	CurrentInteractionIndex int
	Server                  *httptest.Server
}

----------------------------------------------------------------------------- Wrapper of a mock HTTP server that uses HTTP interactions to handle requests -----------------------------------------------------------------------------

func NewMockHttpServer added in v0.37.0

func NewMockHttpServer(t *testing.T, interactions []HttpInteraction) MockHttpServer

type MockTimeService

type MockTimeService struct {
	MockNow time.Time
}

func NewMockTimeServiceAsMock

func NewMockTimeServiceAsMock(now time.Time) *MockTimeService

func (*MockTimeService) Interrupt

func (ts *MockTimeService) Interrupt(message string)

func (*MockTimeService) Now

func (ts *MockTimeService) Now() time.Time

func (*MockTimeService) Sleep

func (ts *MockTimeService) Sleep(duration time.Duration)

type OSEnvironment

type OSEnvironment struct {
}

func NewOSEnvironment

func NewOSEnvironment() *OSEnvironment

NewOSEnvironment creates a real wrapper over the os environment

func (OSEnvironment) GetEnv

func (osEnv OSEnvironment) GetEnv(propertyName string) string

func (OSEnvironment) GetUserName

func (osEnv OSEnvironment) GetUserName() (string, error)

type RealConsole

type RealConsole struct {
}

------------------------------------------------- A real implementation which writes text to stdout.

func NewRealConsole

func NewRealConsole() *RealConsole

func (*RealConsole) Write

func (*RealConsole) Write(p []byte) (n int, err error)

func (*RealConsole) WriteString

func (*RealConsole) WriteString(text string) error

type RunsSubmitCmdValues

type RunsSubmitCmdValues struct {
	PollIntervalSeconds           int
	NoExitCodeOnTestFailures      bool
	ReportYamlFilename            string
	ReportJsonFilename            string
	ReportJunitFilename           string
	GroupName                     string
	ProgressReportIntervalMinutes int
	Throttle                      int
	Overrides                     []string
	Trace                         bool
	Requestor                     string
	RequestType                   string
	ThrottleFileName              string
	PortfolioFileName             string
	OverrideFilePath              string
	TestSelectionFlagValues       *TestSelectionFlagValues
}

RunsSubmitCmdParameters - Holds variables set by cobra's command-line parsing. We collect the parameters here so that our unit tests can feed in different values easily.

type TestSelectionFlagValues

type TestSelectionFlagValues struct {
	Bundles     *[]string
	Packages    *[]string
	Tests       *[]string
	Tags        *[]string
	Classes     *[]string
	Stream      string
	RegexSelect *bool
	GherkinUrl  *[]string
}

Jump to

Keyboard shortcuts

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