utils

package
v1.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

var Protocols = [...]schema.EndpointProtocol{schema.HTTPEndpointProtocol, schema.HTTPSEndpointProtocol, schema.WSEndpointProtocol, schema.WSSEndpointProtocol, schema.TCPEndpointProtocol, schema.UDPEndpointProtocol}

View Source
var RndSeed int64 = time.Now().UnixNano()
View Source
var StringCount int = 0

Functions

func AddSuffixToFileName

func AddSuffixToFileName(fileName string, suffix string) string

AddSuffixToFileName adds a specified suffix to the name of a specified file. For example if the file is devfile.yaml and the suffix is 1, the result is devfile1.yaml

func CreateTempDir

func CreateTempDir(subdir string) string

CreateTempDir creates a specified sub directory under the temp directory if it does not exist. Returns the name of the created directory.

func GetBinaryDecision

func GetBinaryDecision() bool

GetBinaryDecision randomly returns true or false

func GetDevFileName

func GetDevFileName() string

GetDevFileName returns a qualified name of a devfile for use in a test. The devfile will be in a temporary directory and is named using the calling function's name.

func GetRandomDecision

func GetRandomDecision(success int, failure int) bool

GetRandomDecision randomly returns true or false, but weighted to one or the other. For example if success is set to 2 and failure to 1, true is twice as likely to be returned.

func GetRandomGroupKind

func GetRandomGroupKind() schema.CommandGroupKind

GetRandomGroupKind return random group kind. One of "build", "run", "test" or "debug"

func GetRandomNumber

func GetRandomNumber(max int) int

GetRandomNumber randomly returns an integer between 1 and the number specified.

func GetRandomString

func GetRandomString(n int, lower bool) string

GetRandomString returns a random string which is n characters long. If lower is set to true a lower case string is returned.

func GetRandomUniqueString

func GetRandomUniqueString(n int, lower bool) string

GetRandomUniqueString returns a unique random string which is n characters long plus an integer to ensure uniqueness If lower is set to true a lower case string is returned.

func LogErrorMessage

func LogErrorMessage(message string) string

LogErrorMessage logs the specified message as an error message and returns the message logged

func LogInfoMessage

func LogInfoMessage(message string) string

LogInfoMessage logs the specified message as an info message and returns the message logged

func LogMessage

func LogMessage(message string) string

LogMessage logs the specified message and returns the message logged

Types

type TestDevfile

type TestDevfile struct {
	SchemaDevFile schema.Devfile
	FileName      string
	ParserData    devfileData.DevfileData
	SchemaParsed  bool
	GroupDefaults map[schema.CommandGroupKind]bool
	UsedPorts     map[int]bool
}

TestDevfile is a structure used to track a test devfile and its contents

func GetDevfile

func GetDevfile(fileName string) (TestDevfile, error)

GetDevfile returns a structure used to represent a specific devfile in a test

func (*TestDevfile) AddCommand

func (devfile *TestDevfile) AddCommand(commandType schema.CommandType) schema.Command

AddCommand creates a command of a specified type in a schema structure and pupulates it with random attributes

func (*TestDevfile) AddComponent

func (devfile *TestDevfile) AddComponent(componentType schema.ComponentType) schema.Component

AddComponent adds a component of the specified type, with random attributes, to the devfile schema

func (*TestDevfile) CreateEndpoints

func (devfile *TestDevfile) CreateEndpoints() []schema.Endpoint

CreateEndpoints creates and returns a randon number of endpoints in a schema structure

func (*TestDevfile) EditCommands

func (devfile *TestDevfile) EditCommands() error

EditCommands modifies random attributes for each of the commands in the devfile.

func (*TestDevfile) EditComponents

func (devfile *TestDevfile) EditComponents() error

EditComponents modifies random attributes for each of the components in the devfile.

func (*TestDevfile) GetContainerName

func (devfile *TestDevfile) GetContainerName() string

GetContainer returns the name of an existing, or newly created, container.

func (*TestDevfile) UpdateCommand

func (devfile *TestDevfile) UpdateCommand(commandId string) error

UpdateCommand randomly updates attribute values of a specified command in the devfile schema

func (*TestDevfile) UpdateComponent

func (devfile *TestDevfile) UpdateComponent(componentName string) error

UpdateComponent randomly updates the attribute values of a specified component

func (*TestDevfile) Verify

func (devfile *TestDevfile) Verify() error

Verify verifies the contents of the specified devfile with the expected content

func (*TestDevfile) VerifyCommands

func (devfile *TestDevfile) VerifyCommands(parserCommands []schema.Command) error

VerifyCommands verifies commands returned by the parser are the same as those saved in the devfile schema

func (*TestDevfile) VerifyComponents

func (devfile *TestDevfile) VerifyComponents(parserComponents []schema.Component) error

VerifyComponents verifies components returned by the parser are the same as those saved in the devfile schema

func (*TestDevfile) WriteDevfile

func (devfile *TestDevfile) WriteDevfile(useParser bool) error

WriteDevfile create a devifle on disk for use in a test. If useParser is true the parser library is used to generate the file, otherwise "sigs.k8s.io/yaml" is used.

Jump to

Keyboard shortcuts

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