{"modulePath":"github.com/galasa-dev/cli","version":"v0.41.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n\\* Copyright contributors to the Galasa project \\* \\* SPDX-License-Identifier: EPL-2.0\n\n## Constants\n\n```go\nconst (\n\tLOWER_CASE_LETTERS = \"abcdefghijklmnopqrstuvwxyz\"\n\tDIGITS             = \"0123456789\"\n\tSEPARATOR          = \".\"\n)\n```\n\n```go\nconst (\n\tMAVEN_REPO_URL_GALASA_BLEEDING_EDGE = \"https://development.galasa.dev/main/maven-repo/obr\"\n\tMAVEN_REPO_URL_MAVEN_CENTRAL        = \"https://repo.maven.apache.org/maven2\"\n)\n```\n\n```go\nconst (\n\tSECONDS_BETWEEN_INTERRUPTED_CHECKS  = 3\n\tDURATION_BETWEEN_INTERRUPTED_CHECKS = SECONDS_BETWEEN_INTERRUPTED_CHECKS * time.Second\n)\n```\n\n```go\nconst (\n\t// The maximum value we can cope with for the encryption.\n\t// We hold all the data in memory so need to be defensive we don't try to encrypt too much.\n\tMAX_TEXT_TO_ENCRYPT = 2048\n)\n```\n\n## Functions\n\n```go\nfunc AddJavaRuntimeToMock(fileSystem spi.FileSystem, baseJavaFolderName string)\n```\n\n```go\nfunc CalculateMaxLengthOfEachColumn(table [][]string) []int\n```\n\\----------------------------------------------------- Functions for tables\n\n```go\nfunc CaptureExecutionLogs(factory spi.Factory, logFileName string, executionFunc func() error) error\n```\nCaptureExecutionLogs captures the logs for a given execution function to a file or stderr.\n\n```go\nfunc CaptureLog(fileSystem spi.FileSystem, logFileName string) error\n```\n\\* 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.\n\n```go\nfunc Decrypt(secret string, encryptedText string) (string, error)\n```\n\n```go\nfunc DeleteAllBearerTokenFiles(fileSystem spi.FileSystem, galasaHome spi.GalasaHome) error\n```\n\n```go\nfunc Encrypt(secret string, textToEncrypt string) (string, error)\n```\n\n```go\nfunc FormatTimeToNearestDate(rawTime string) string\n```\n\n```go\nfunc FormatTimeToNearestDateTimeMins(rawTime string) string\n```\n\\----------------------------------------------------- Functions for time formats and duration\n\n```go\nfunc GetGalasaBootJarPath(fs spi.FileSystem, home spi.GalasaHome) (string, error)\n```\n\n```go\nfunc InitialiseGalasaHomeFolder(home spi.GalasaHome, fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem) error\n```\n\n```go\nfunc InitialiseM2Folder(fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem, isDevelopment bool) error\n```\n\n```go\nfunc IsAlphanumeric(str string) bool\n```\nIsAlphanumeric - Checks if a given string contains only alphanumeric characters\n\n```go\nfunc IsCharacterAlphanumeric(character rune) bool\n```\n\n```go\nfunc IsLatin1(str string) bool\n```\nChecks if a given string contains only characters in the Latin-1 character set (codepoints 0-255), returning true if so, and false otherwise\n\n```go\nfunc IsNameValid(name string) bool\n```\nIsNameValid - Checks if a given string used as a name for a structure (e.g. role, secret, group, etc.) only contains the following characters: - Alphanumeric characters (a-z, A-Z, 0-9) - Dashes (-) - Underscores (\\_)\n\n```go\nfunc ListAllBearerTokenFiles(fileSystem spi.FileSystem, galasaHome spi.GalasaHome) ([]string, error)\n```\n\n```go\nfunc NewByteReader() spi.ByteReader\n```\n\n```go\nfunc NewEnvironment() spi.Environment\n```\n\n```go\nfunc NewGalasaHome(fs spi.FileSystem, env spi.Environment, cmdFlagGalasaHome string) (spi.GalasaHome, error)\n```\n\n```go\nfunc NewMockByteReader() spi.ByteReader\n```\n\n```go\nfunc NewMockFinalWordHandler() spi.FinalWordHandler\n```\n\n```go\nfunc NewOverridableMockTimeService(now time.Time) spi.TimeService\n```\n\n```go\nfunc NewRealTimeService() spi.TimeService\n```\n\n```go\nfunc NewRealTimedSleeper() spi.TimedSleeper\n```\n\n```go\nfunc StringWithNewLinesInsteadOfCRLFs(input string) string\n```\nWalks throught the input string and converts : 0x0d characters to 0x0a (NewLine) characters 0x0d 0x0c (CR-LF) to 0x0a (NewLine) characters\n\nso that the entire string can be printed using Golang printf/println without line endings being mangled.\n\n```go\nfunc UppercaseFirstLetter(s string) string\n```\nUppercaseFirstLetter - takes a string and returns the same string, but with the first letter turned into an uppercase letter.\n\n```go\nfunc ValidateJavaHome(fileSystem spi.FileSystem, javaHome string) error\n```\nvalidateJavaHome 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.\n\nConstraints: - It must be set. - JAVA\\_HOME/bin must be a folder which exists. - JAVA\\_HOME/bin/java must exist as a file.\n\n```go\nfunc ValidateJavaPackageName(javaPackageName string) error\n```\nTo validate the string as a valid java package name before we start to use it.\n\n```go\nfunc WriteFormattedTableToStringBuilder(table [][]string, buff *strings.Builder, columnLengths []int)\n```\n\n## Types\n\n```go\ntype BearerTokenFile interface {\n\tWriteJwt(jwt string, encryptionSecret string) error\n\tReadJwt(encryptionSecret string) (string, error)\n\tDeleteJwt() error\n\tExists() (bool, error)\n}\n```\n\n```go\nfunc NewBearerTokenFile(\n\tfileSystem spi.FileSystem,\n\tgalasaHome spi.GalasaHome,\n\tbaseFileName string,\n\ttimeService spi.TimeService,\n) BearerTokenFile\n```\n\n```go\ntype BearerTokenFileImpl struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (file *BearerTokenFileImpl) DeleteJwt() error\n```\n\n```go\nfunc (file *BearerTokenFileImpl) Exists() (bool, error)\n```\n\n```go\nfunc (file *BearerTokenFileImpl) ReadJwt(encryptionSecret string) (string, error)\n```\nGets the JWT from the bearer-token.json file if it exists, errors if the file does not exist or if the token is invalid\n\n```go\nfunc (file *BearerTokenFileImpl) WriteJwt(jwt string, encryptionSecret string) error\n```\nWrites a new bearer-token.json file containing a JWT in the following format:\n\n\t{\n\t  \"jwt\": \"\u003cbearer-token-here\u003e\"\n\t}\n\n```go\ntype BearerTokenJson struct {\n\tJwt string `json:\"jwt\"`\n}\n```\n\n```go\ntype BlankTemplateParameters struct{}\n```\n\n```go\ntype ByteReaderImpl struct {\n}\n```\nImplementation of a byte reader to allow mocking out methods from the io package\n\n```go\nfunc (*ByteReaderImpl) ReadAll(reader io.Reader) ([]byte, error)\n```\n\n```go\ntype FileGenerator struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewFileGenerator(fileSystem spi.FileSystem, embeddedFileSystem embedded.ReadOnlyFileSystem) *FileGenerator\n```\n\n```go\nfunc (generator *FileGenerator) CreateFile(\n\tgeneratedFile GeneratedFileDef,\n\tforceOverwrite bool,\n\tisExistsAnError bool) error\n```\ncreateFile creates a file on the file system. If forceOverwrite is false, and there is already a file there, then an error will occur.\n\n```go\nfunc (generator *FileGenerator) CreateFolder(targetFolderPath string) error\n```\n\n```go\ntype GeneratedFileDef struct {\n\tFileType                 string\n\tTargetFilePath           string\n\tEmbeddedTemplateFilePath string\n\tTemplateParameters       interface{}\n}\n```\n\n```go\ntype HttpInteraction struct {\n\tExpectedPath       string\n\tExpectedHttpMethod string\n\n\t// An override-able function to write a HTTP response for this interaction\n\tWriteHttpResponseFunc func(writer http.ResponseWriter, req *http.Request)\n\n\tValidateRequestFunc func(t *testing.T, req *http.Request)\n}\n```\nThe 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)\n\n```go\nfunc NewHttpInteraction(expectedPath string, expectedHttpMethod string) HttpInteraction\n```\n\n```go\nfunc (interaction *HttpInteraction) ValidateRequest(t *testing.T, req *http.Request)\n```\n\n```go\ntype JavaClassDef struct {\n\tPackageName string\n\tClassName   string\n}\n```\n\n```go\ntype MavenCoordinates struct {\n\tGroupId    string\n\tArtifactId string\n\tVersion    string\n\tClassifier string\n}\n```\n\n```go\nfunc ValidateObr(obr string) (MavenCoordinates, error)\n```\nWe 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.\n\n```go\nfunc ValidateObrs(obrInputs []string) ([]MavenCoordinates, error)\n```\nWe 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.\n\n```go\ntype MockAuthenticator struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewMockAuthenticator() *MockAuthenticator\n```\n\n```go\nfunc NewMockAuthenticatorWithAPIClient(apiClient *galasaapi.APIClient) *MockAuthenticator\n```\n\n```go\nfunc (authenticator *MockAuthenticator) GetAuthenticatedAPIClient() (*galasaapi.APIClient, error)\n```\nGets a new authenticated API client, attempting to log in if a bearer token file does not exist\n\n```go\nfunc (authenticator *MockAuthenticator) GetBearerToken() (string, error)\n```\n\n```go\nfunc (authenticator *MockAuthenticator) Login() error\n```\nLogin - performs all the logic to implement the \\`galasactl auth login\\` command\n\n```go\nfunc (authenticator *MockAuthenticator) LogoutOfEverywhere() error\n```\nLogin - performs all the logic to implement the \\`galasactl auth login\\` command\n\n```go\nfunc (authenticator *MockAuthenticator) SetHttpStatusCodeToReturn(httpStatusCodeToReturn int)\n```\n\n```go\ntype MockByteReader struct {\n\t// contains filtered or unexported fields\n}\n```\nMock implementation of a byte reader to allow for simulating failed read operations\n\n```go\nfunc NewMockByteReaderAsMock(throwReadError bool) *MockByteReader\n```\n\n```go\nfunc (mockReader *MockByteReader) ReadAll(reader io.Reader) ([]byte, error)\n```\n\n```go\ntype MockConsole struct {\n\t// contains filtered or unexported fields\n}\n```\n\\------------------------------------------------- A mock implementation which writes text to a buffer Useful for unit testing.\n\n```go\nfunc NewMockConsole() *MockConsole\n```\n\n```go\nfunc (data *MockConsole) ReadText() string\n```\n\n```go\nfunc (data *MockConsole) Write(p []byte) (n int, err error)\n```\n\n```go\nfunc (this *MockConsole) WriteString(text string) error\n```\n\n```go\ntype MockEnv struct {\n\tEnvVars map[string]string\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewMockEnv() *MockEnv\n```\n\n```go\nfunc (env *MockEnv) GetEnv(propertyName string) string\n```\n\n```go\nfunc (env *MockEnv) GetUserName() (string, error)\n```\n\n```go\nfunc (env *MockEnv) SetEnv(propertyName string, value string)\n```\n\n```go\nfunc (env *MockEnv) SetUserName(name string)\n```\n\n```go\ntype MockFactory struct {\n\tFinalWordHandler spi.FinalWordHandler\n\tFileSystem       spi.FileSystem\n\tEnv              spi.Environment\n\tStdOutConsole    spi.Console\n\tStdErrConsole    spi.Console\n\tTimeService      spi.TimeService\n\tAuthenticator    spi.Authenticator\n\tByteReader       spi.ByteReader\n}\n```\n\n```go\nfunc NewMockFactory() *MockFactory\n```\n\n```go\nfunc (factory *MockFactory) GetAuthenticator(apiServerUrl string, galasaHome spi.GalasaHome) spi.Authenticator\n```\n\n```go\nfunc (factory *MockFactory) GetByteReader() spi.ByteReader\n```\n\n```go\nfunc (factory *MockFactory) GetEnvironment() spi.Environment\n```\n\n```go\nfunc (factory *MockFactory) GetFileSystem() spi.FileSystem\n```\n\n```go\nfunc (factory *MockFactory) GetFinalWordHandler() spi.FinalWordHandler\n```\n\n```go\nfunc (factory *MockFactory) GetStdErrConsole() spi.Console\n```\n\n```go\nfunc (factory *MockFactory) GetStdOutConsole() spi.Console\n```\n\n```go\nfunc (factory *MockFactory) GetTimeService() spi.TimeService\n```\n\n```go\ntype MockFinalWordHandler struct {\n\tReportedObject interface{}\n}\n```\n\n```go\nfunc (handler *MockFinalWordHandler) FinalWord(rootCmd spi.GalasaCommand, errorToExctractFrom interface{})\n```\n\n```go\ntype MockHttpServer struct {\n\tCurrentInteractionIndex int\n\tServer                  *httptest.Server\n}\n```\n\\----------------------------------------------------------------------------- Wrapper of a mock HTTP server that uses HTTP interactions to handle requests -----------------------------------------------------------------------------\n\n```go\nfunc NewMockHttpServer(t *testing.T, interactions []HttpInteraction) MockHttpServer\n```\n\n```go\nfunc NewMockHttpServerWithUnorderedInteractions(t *testing.T, unorderedInteractions []HttpInteraction) MockHttpServer\n```\n\n```go\ntype MockTimeService struct {\n\tMockNow time.Time\n}\n```\n\n```go\nfunc NewMockTimeService() *MockTimeService\n```\n\n```go\nfunc NewMockTimeServiceAsMock(now time.Time) *MockTimeService\n```\n\n```go\nfunc (ts *MockTimeService) AdvanceClock(duration time.Duration)\n```\n\n```go\nfunc (ts *MockTimeService) Now() time.Time\n```\n\n```go\nfunc (ts *MockTimeService) Sleep(duration time.Duration)\n```\n\n```go\ntype OSEnvironment struct {\n}\n```\n\n```go\nfunc NewOSEnvironment() *OSEnvironment\n```\nNewOSEnvironment creates a real wrapper over the os environment\n\n```go\nfunc (osEnv OSEnvironment) GetEnv(propertyName string) string\n```\n\n```go\nfunc (osEnv OSEnvironment) GetUserName() (string, error)\n```\n\n```go\ntype RealConsole struct {\n}\n```\n\\------------------------------------------------- A real implementation which writes text to stdout.\n\n```go\nfunc NewRealConsole() *RealConsole\n```\n\n```go\nfunc (*RealConsole) Write(p []byte) (n int, err error)\n```\n\n```go\nfunc (*RealConsole) WriteString(text string) error\n```\n\n```go\ntype RunsSubmitCmdValues struct {\n\tPollIntervalSeconds           int\n\tNoExitCodeOnTestFailures      bool\n\tReportYamlFilename            string\n\tReportJsonFilename            string\n\tReportJunitFilename           string\n\tGroupName                     string\n\tProgressReportIntervalMinutes int\n\tThrottle                      int\n\tOverrides                     []string\n\tTrace                         bool\n\tRequestor                     string\n\tRequestType                   string\n\tThrottleFileName              string\n\tPortfolioFileName             string\n\tOverrideFilePaths             []string\n\tTestSelectionFlagValues       *TestSelectionFlagValues\n}\n```\nRunsSubmitCmdParameters - 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.\n\n```go\ntype TestSelectionFlagValues struct {\n\tBundles     *[]string\n\tPackages    *[]string\n\tTests       *[]string\n\tTags        *[]string\n\tClasses     *[]string\n\tStream      string\n\tRegexSelect *bool\n\tGherkinUrl  *[]string\n}\n```\n\n","path":"github.com/galasa-dev/cli/pkg/utils","name":"utils","synopsis":"* Copyright contributors to the Galasa project * * SPDX-License-Identifier: EPL-2.0","isRedistributable":true}
