common

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegistry = "localhost:50000/user"
)

Intended to provide setup configuration for E2E tests

Variables

This section is empty.

Functions

func CleanOutput added in v0.37.0

func CleanOutput(stdOutput string) string

CleanOutput Some commands, such as deploy command, spans spinner chars and cursor shifts at output which are captured and merged regular output messages. This functions is meant to remove these chars in order to facilitate tests assertions and data extraction from output

func GetCurrentServiceRevision added in v0.37.0

func GetCurrentServiceRevision(t *testing.T, serviceName string) string

GetCurrentServiceRevision retrieves current revision name for the deployed function

func GetFuncBinaryPath added in v0.37.0

func GetFuncBinaryPath() string

GetFuncBinaryPath should return the Path of 'func' binary under test

func GetKnativeServiceRevisionAndUrl added in v0.37.0

func GetKnativeServiceRevisionAndUrl(t *testing.T, serviceName string) (revision string, url string)

func GetOsEnvOrDefault added in v0.37.0

func GetOsEnvOrDefault(env string, dflt string) string

func GetRegistry added in v0.37.0

func GetRegistry() string

GetRegistry returns registry

func GetRuntime added in v0.37.0

func GetRuntime() string

GetRuntime returns the runtime that should be tested.

func IsUseKnFunc added in v0.37.0

func IsUseKnFunc() bool

IsUseKnFunc indicates that tests should be run against "kn func" instead of "func" binary

func RetrieveKnativeServiceResource added in v0.37.0

func RetrieveKnativeServiceResource(t *testing.T, serviceName string) *unstructured.Unstructured

RetrieveKnativeServiceResource wraps the logic to query knative serving resources in current namespace

func WaitForFunctionReady added in v0.37.0

func WaitForFunctionReady(t *testing.T, functionName string) (revisionName string, functionUrl string)

func WaitForNewRevisionReady added in v0.37.0

func WaitForNewRevisionReady(t *testing.T, previousRevision string, functionName string) (newRevision string)

NewRevisionCheck waits for a new revision to report as ready

Types

type GitProvider

type GitProvider interface {
	Init(T *testing.T)
	CreateRepository(repoName string) *GitRemoteRepo
	DeleteRepository(repoName string)
}

func GetGitServer

func GetGitServer(T *testing.T) GitProvider

type GitRemoteRepo

type GitRemoteRepo struct {
	RepoName         string
	ExternalCloneURL string
	ClusterCloneURL  string
}

type GitTestServerProvider

type GitTestServerProvider struct {
	PodName    string
	ServiceUrl string
	Kubectl    *TestExecCmd
	// contains filtered or unexported fields
}

func (*GitTestServerProvider) CreateRepository

func (g *GitTestServerProvider) CreateRepository(repoName string) *GitRemoteRepo

func (*GitTestServerProvider) DeleteRepository

func (g *GitTestServerProvider) DeleteRepository(repoName string)

func (*GitTestServerProvider) Init

func (g *GitTestServerProvider) Init(T *testing.T)

type TestExecCmd

type TestExecCmd struct {

	// binary to invoke
	// Example: "func", "kn", "kubectl", "/usr/bin/sh"
	Binary string

	// Binary args to append before actual args. Examples:
	//  when 'kn' binary binaryArgs should be ["func"]
	BinaryArgs []string

	// Run commands from Dir
	SourceDir string

	// Indicates shell should dump command line args during execution
	ShouldDumpCmdLine bool

	// Indicates shell should dump
	ShouldDumpOnSuccess bool

	// Fail Test on Error
	ShouldFailOnError bool

	// Environment variable to be used with the command
	Env []string

	// Optional function to be used to dump stdout command results
	DumpLogger func(out string)

	// Access to Running or Latest command
	ExecCmd *exec.Cmd

	// Function to be executed while the command is running. This function is executed only once
	OnWaitCallback func(stdout *bytes.Buffer)

	// Function to be executed after the command is completed (before error and cmd stdout logic is executed)
	OnFinishCallback func(result *TestExecCmdResult)

	T *testing.T
}

func NewKnFuncShellCli

func NewKnFuncShellCli(t *testing.T) *TestExecCmd

func NewShellCmd

func NewShellCmd(t *testing.T, fromDirectory string) *TestExecCmd

func (*TestExecCmd) Exec

func (f *TestExecCmd) Exec(args ...string) TestExecCmdResult

Exec invokes go exec library and runs a shell command combining the binary args with args from method signature

func (*TestExecCmd) FromDir

func (f *TestExecCmd) FromDir(dir string) *TestExecCmd

func (*TestExecCmd) Run

func (f *TestExecCmd) Run(oneArgs string) TestExecCmdResult

func (*TestExecCmd) WithEnv

func (f *TestExecCmd) WithEnv(envKey string, envValue string) *TestExecCmd

type TestExecCmdResult

type TestExecCmdResult struct {
	Out   string
	Error error
}

TestExecCmdResult stored command result

type TestInteractiveCmd added in v0.37.0

type TestInteractiveCmd struct {
	TestCmd *TestExecCmd
	T       *testing.T

	// Sleep interval before first command input
	StartSleepInterval time.Duration

	// Sleep interval between each subcommand
	CommandSleepInterval time.Duration

	// Sleep interval after last command completion.
	// Required time to give to process to complete before EOF
	CompletionSleepInterval time.Duration

	// Timeout before kill the cmd in case of some failure
	CompletionTimeout time.Duration
}

func NewTestShellInteractiveCmd added in v0.37.0

func NewTestShellInteractiveCmd(t *testing.T) *TestInteractiveCmd

func (*TestInteractiveCmd) PrepareRun added in v0.37.0

func (f *TestInteractiveCmd) PrepareRun(funcCommand ...string) func(args ...string) TestExecCmdResult

PrepareRun creates a go function used to start kn func (binary) that requires user interaction such as `func config command`

Jump to

Keyboard shortcuts

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