test

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

OutputCapture allows to capture any text written to standard out or standard error which is especially useful during testing.

Call it like:

capture := CaptureOutput(t) doSomeActionThatWritesToStdOutAndStdErr() stdOut, stdErr := capture.Close()

CaptureOutput() and capture.Close() should always come in pairs as Close() also restores the old streams

Index

Constants

View Source
const (
	MaxRetries         int           = 10
	RetrySleepDuration time.Duration = 5 * time.Second
)
View Source
const (
	FileModeReadWrite  = 0666
	FileModeExecutable = 0777
)

Variables

Flags holds the command line flags or defaults for settings in the user's environment. See ClientFlags for the list of supported fields.

Functions

func BrokerCreate added in v0.25.0

func BrokerCreate(r *KnRunResultCollector, name string)

BrokerCreate creates a broker with the given name.

func BrokerCreateWithClass added in v0.25.0

func BrokerCreateWithClass(r *KnRunResultCollector, name, class string)

BrokerCreateWithClass creates a broker with the given name and class.

func BrokerDelete added in v0.25.0

func BrokerDelete(r *KnRunResultCollector, name string, wait bool)

BrokerDelete deletes a broker with the given name.

func BuildConfigurationSpec added in v0.19.0

func BuildConfigurationSpec(co ...servingtest.ConfigOption) *servingv1.ConfigurationSpec

BuildConfigurationSpec builds servingv1.ConfigurationSpec with the options provided

func BuildKNExportWithOptions added in v0.19.0

func BuildKNExportWithOptions(options ...ExpectedKNExportOption) *clientv1alpha1.Export

BuildKNExportWithOptions returns Export object with the options provided

func BuildRevision added in v0.19.0

func BuildRevision(name string, options ...servingtest.RevisionOption) *servingv1.Revision

BuildRevision returns Revision object with the options provided

func BuildRevisionListWithOptions added in v0.19.0

func BuildRevisionListWithOptions(options ...ExpectedRevisionListOption) *servingv1.RevisionList

BuildRevisionListWithOptions returns RevisionList with options provided

func BuildRevisionSpec added in v0.19.0

func BuildRevisionSpec(image string) *servingv1.RevisionSpec

BuildRevisionSpec for provided image

func BuildServiceListWithOptions added in v0.19.0

func BuildServiceListWithOptions(options ...ExpectedServiceListOption) *servingv1.ServiceList

BuildServiceListWithOptions returns ServiceList with options provided

func BuildServiceWithOptions added in v0.19.0

func BuildServiceWithOptions(name string, so ...servingtest.ServiceOption) *servingv1.Service

BuildServiceWithOptions returns ksvc with options provided

func ChannelCreate added in v0.17.0

func ChannelCreate(r *KnRunResultCollector, cname string, args ...string)

func ChannelDelete added in v0.17.0

func ChannelDelete(r *KnRunResultCollector, cname string)

func ChannelDescribe added in v0.17.0

func ChannelDescribe(r *KnRunResultCollector, cname string, args ...string) string

func ChannelList added in v0.17.0

func ChannelList(r *KnRunResultCollector, args ...string) string

func ChannelListTypes added in v0.18.0

func ChannelListTypes(r *KnRunResultCollector, args ...string) string

ChannelListTypes return available channel types

func CreateFile added in v0.15.0

func CreateFile(fileName, fileContent, filePath string, fileMode os.FileMode) (string, error)

CreateFile creates a file with given name, content, path, fileMode and returns absolute filepath and error if any

func CreateNamespace

func CreateNamespace(namespace string) error

CreateNamespace creates and tests a namespace creation invoking kubectl

func CurrentDir

func CurrentDir(t *testing.T) string

func DeleteNamespace

func DeleteNamespace(namespace string) error

DeleteNamespace deletes and tests a namespace deletion invoking kubectl

func EventtypeCreate added in v0.30.0

func EventtypeCreate(r *KnRunResultCollector, name, cetype string)

EventtypeCreate creates an eventtype with the given name.

func EventtypeCreateWithBrokerSource added in v0.30.0

func EventtypeCreateWithBrokerSource(r *KnRunResultCollector, name, cetype, broker, source string)

func EventtypeCreateWithSourceError added in v0.30.0

func EventtypeCreateWithSourceError(r *KnRunResultCollector, name, cetype, source string)

func EventtypeDelete added in v0.30.0

func EventtypeDelete(r *KnRunResultCollector, name string)

EventtypeDelete deletes an eventtype with the given name.

func EventtypeDescribe added in v0.30.0

func EventtypeDescribe(r *KnRunResultCollector, name string)

EventtypeDescribe describes an eventtype with the given name.

func EventtypeList added in v0.30.0

func EventtypeList(r *KnRunResultCollector, eventtypes ...string)

EventtypeList verifies listing eventtypes in the given namespace

func FindConfigurationGeneration added in v0.15.0

func FindConfigurationGeneration(r *KnRunResultCollector, serviceName string) int

FindConfigurationGeneration returns the configuration generation number of given service

func FindRevision added in v0.15.0

func FindRevision(r *KnRunResultCollector, serviceName string) string

FindRevision returns a revision name (at index 0) for given service

func FindRevisionByGeneration added in v0.15.0

func FindRevisionByGeneration(r *KnRunResultCollector, serviceName string, generation int) string

FindRevisionByGeneration returns a revision name for given revision at given generation number

func GetNextNamespaceId

func GetNextNamespaceId() int

GetNextNamespaceId return the next unique ID for the next namespace

func GetNextServiceName

func GetNextServiceName(base string) string

GetNextServiceName return the name for the next namespace

func GetResourceFieldsWithJSONPath added in v0.15.0

func GetResourceFieldsWithJSONPath(t *testing.T, it *KnTest, resource, name, jsonpath string) (string, error)

GetResourceFieldsWithJSONPath returns output of given JSON path for given resource using kubectl and error if any

func GetServiceFromKNServiceDescribe added in v0.18.0

func GetServiceFromKNServiceDescribe(r *KnRunResultCollector, serviceName string) servingv1.Service

GetServiceFromKNServiceDescribe runs the kn service describe command decodes it into a ksvc and returns it.

func LabelNamespaceForDefaultBroker added in v0.16.0

func LabelNamespaceForDefaultBroker(r *KnRunResultCollector) error

LabelNamespaceForDefaultBroker adds label 'knative-eventing-injection=enabled' to the configured namespace

func NextNamespace

func NextNamespace() string

NextNamespace return the next unique namespace

func RevisionDelete added in v0.15.0

func RevisionDelete(r *KnRunResultCollector, revName string)

RevisionDelete verifies deleting given revision in sync mode

func RevisionDeleteWithPruneAllOption added in v0.22.0

func RevisionDeleteWithPruneAllOption(r *KnRunResultCollector, revName1, revName2 string)

RevisionDeleteWithPruneAllOption verifies removeing all unreferenced revision in sync mode

func RevisionDeleteWithPruneOption added in v0.22.0

func RevisionDeleteWithPruneOption(r *KnRunResultCollector, serviceName, revName string)

RevisionDeleteWithPruneOption verifies removeing all unreferenced revisions for a given service in sync mode

func RevisionDescribe added in v0.15.0

func RevisionDescribe(r *KnRunResultCollector, serviceName string)

RevisionDescribe verifies revision describe output for given service's revision

func RevisionDescribeWithPrintFlags added in v0.15.0

func RevisionDescribeWithPrintFlags(r *KnRunResultCollector, revName string)

RevisionDescribeWithPrintFlags verifies describing given revision using print flag '--output=name'

func RevisionListForService added in v0.15.0

func RevisionListForService(r *KnRunResultCollector, serviceName string)

RevisionListForService list revisions of given service and verifies if their status is True

func RevisionListOutputName added in v0.15.0

func RevisionListOutputName(r *KnRunResultCollector, revisionName string)

RevisionListOutputName verifies listing given revision using print flag '--output name'

func RevisionListWithService added in v0.15.0

func RevisionListWithService(r *KnRunResultCollector, serviceNames ...string)

RevisionListWithService verifies listing revisions per service from each given service names

func RevisionMultipleDelete added in v0.15.0

func RevisionMultipleDelete(r *KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string)

RevisionMultipleDelete verifies deleting multiple revisions

func RunKubectl

func RunKubectl(namespace string, args ...string) (string, error)

RunKubectl runs "kubectl" in a given namespace

func ServiceCreate added in v0.15.0

func ServiceCreate(r *KnRunResultCollector, serviceName string)

ServiceCreate verifies given service creation in sync mode and also verifies output

func ServiceDelete added in v0.15.0

func ServiceDelete(r *KnRunResultCollector, serviceName string)

ServiceDelete verifies service deletion in sync mode

func ServiceDescribe added in v0.15.0

func ServiceDescribe(r *KnRunResultCollector, serviceName string)

ServiceDescribe describes given service and verifies the keys in the output

func ServiceDescribeWithJSONPath added in v0.15.0

func ServiceDescribeWithJSONPath(r *KnRunResultCollector, serviceName, jsonpath string) string

ServiceDescribeWithJSONPath returns output of given JSON path by describing the service

func ServiceList added in v0.15.0

func ServiceList(r *KnRunResultCollector, serviceName string)

ServiceList verifies if given service exists

func ServiceListEmpty added in v0.15.0

func ServiceListEmpty(r *KnRunResultCollector)

ServiceListEmpty verifies that there are no services present

func ServiceListOutput added in v0.15.0

func ServiceListOutput(r *KnRunResultCollector, serviceName string)

ServiceListOutput verifies listing given service using '--output name' flag

func ServiceUpdate added in v0.15.0

func ServiceUpdate(r *KnRunResultCollector, serviceName string, args ...string)

ServiceUpdate verifies service update operation with given arguments in sync mode

func ServiceUpdateWithError added in v0.15.2

func ServiceUpdateWithError(r *KnRunResultCollector, serviceName string, args ...string)

ServiceUpdateWithError verifies service update operation with given arguments in sync mode when expecting an error

func SubscriptionCreate added in v0.17.1

func SubscriptionCreate(r *KnRunResultCollector, sname string, args ...string)

func SubscriptionDelete added in v0.17.1

func SubscriptionDelete(r *KnRunResultCollector, sname string)

func SubscriptionDescribe added in v0.17.1

func SubscriptionDescribe(r *KnRunResultCollector, sname string, args ...string) string

func SubscriptionList added in v0.17.1

func SubscriptionList(r *KnRunResultCollector, args ...string) string

func SubscriptionUpdate added in v0.17.1

func SubscriptionUpdate(r *KnRunResultCollector, sname string, args ...string)

func UnlabelNamespaceForDefaultBroker added in v0.16.0

func UnlabelNamespaceForDefaultBroker(r *KnRunResultCollector)

UnlabelNamespaceForDefaultBroker removes label 'knative-eventing-injection=enabled' from the configured namespace

func ValidateServiceResources added in v0.15.0

func ValidateServiceResources(r *KnRunResultCollector, serviceName string, requestsMemory, requestsCPU, limitsMemory, limitsCPU string)

ValidateServiceResources validates cpu and mem resources

func WaitForNamespaceCreated

func WaitForNamespaceCreated(namespace string) error

WaitForNamespaceCreated wait until namespace is created

func WaitForNamespaceDeleted

func WaitForNamespaceDeleted(namespace string) error

WaitForNamespaceDeleted wait until namespace is deleted

func WaitForSa added in v0.23.0

func WaitForSa(serviceaccount string, namespace string) error

WaitForSa wait until service account is created

func WithRevisionAnnotations added in v0.19.0

func WithRevisionAnnotations(annotations map[string]string) servingtest.ServiceOption

WithRevisionAnnotations adds annotation to revision spec in ksvc

func WithRevisionEnv added in v0.19.0

func WithRevisionEnv(evs ...corev1.EnvVar) servingtest.RevisionOption

WithRevisionEnv adds env variable to Revision object

func WithRevisionImage added in v0.19.0

func WithRevisionImage(image string) servingtest.RevisionOption

WithRevisionImage adds revision image to Revision object

func WithTrafficSpec added in v0.19.0

func WithTrafficSpec(revisions []string, percentages []int, tags []string) servingtest.ServiceOption

WithTrafficSpec adds route to ksvc

Types

type ClientFlags

type ClientFlags struct {
	DockerConfigJSON string
	ReuseNamespace   bool
}

ClientFlags define the flags that are needed to run the e2e tests.

func InitializeFlags

func InitializeFlags() *ClientFlags

InitializeFlags initializes the client's flags

type ExpectedKNExportOption added in v0.19.0

type ExpectedKNExportOption func(*clientv1alpha1.Export)

ExpectedKNExportOption enables further configuration of a Export.

func WithKNRevision added in v0.19.0

func WithKNRevision(rev servingv1.Revision) ExpectedKNExportOption

WithKNRevision appends Revision object RevisionList to Kn Export

type ExpectedRevisionListOption added in v0.19.0

type ExpectedRevisionListOption func(*servingv1.RevisionList)

ExpectedRevisionListOption enables further configuration of a RevisionList.

func WithRevision added in v0.19.0

WithRevision appends Revision object to RevisionList

type ExpectedServiceListOption added in v0.19.0

type ExpectedServiceListOption func(*servingv1.ServiceList)

ExpectedServiceListOption enables further configuration of a ServiceList.

func WithService added in v0.19.0

WithService appends the given service to ServiceList

type Kn

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

Kn type

func NewKn

func NewKn() Kn

NewKn object

func (Kn) Namespace

func (k Kn) Namespace() string

Namespace that this Kn instance uses

func (Kn) Run

func (k Kn) Run(args ...string) KnRunResult

Run the 'kn' CLI with args

func (Kn) RunNoNamespace added in v0.14.0

func (k Kn) RunNoNamespace(args ...string) KnRunResult

RunNoNamespace the 'kn' CLI with args but no namespace

type KnRunResult

type KnRunResult struct {
	// Command line called
	CmdLine string
	// Standard output of command
	Stdout string
	// Standard error of command
	Stderr string
	// And extra dump informations in case of an unexpected error
	DumpInfo string
	// Error occurred during execution
	Error error
	// Was an error expected ?
	ErrorExpected bool
}

KnRunResult holds command and result artifacts of a "kn" call

func RunKn

func RunKn(namespace string, args []string) KnRunResult

RunKn runs "kn" in a given namespace

type KnRunResultCollector

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

KnRunResultCollector collects Kn run's results

func NewKnRunResultCollector

func NewKnRunResultCollector(t *testing.T, knTest *KnTest) *KnRunResultCollector

NewKnRunResultCollector returns a new KnRunResultCollector

func (*KnRunResultCollector) AddDump

func (c *KnRunResultCollector) AddDump(kind string, name string, namespace string)

AddDump adds extra dump information to the collector which is printed out if an error occurs

func (*KnRunResultCollector) AssertError

func (c *KnRunResultCollector) AssertError(result KnRunResult)

AssertError helper to assert error on result

func (*KnRunResultCollector) AssertNoError

func (c *KnRunResultCollector) AssertNoError(result KnRunResult)

AssertNoError helper to assert no error on result

func (*KnRunResultCollector) Dump added in v0.17.2

func (c *KnRunResultCollector) Dump()

Dump prints out the collected output and logs

func (*KnRunResultCollector) DumpIfFailed

func (c *KnRunResultCollector) DumpIfFailed()

DumpIfFailed logs if collector failed

func (*KnRunResultCollector) KnTest added in v0.14.0

func (c *KnRunResultCollector) KnTest() *KnTest

KnTest returns the KnTest object

func (*KnRunResultCollector) T added in v0.14.0

func (c *KnRunResultCollector) T() *testing.T

T returns the *testing.T object

type KnTest

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

KnTest type

func NewKnTest

func NewKnTest() (*KnTest, error)

NewKnTest creates a new KnTest object

func (*KnTest) Kn

func (test *KnTest) Kn() Kn

Kn object used by this KnTest

func (*KnTest) Namespace

func (test *KnTest) Namespace() string

Namespace used by the test

func (*KnTest) Teardown

func (test *KnTest) Teardown() error

Teardown clean up

type Kubectl

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

Kubectl type

func NewKubectl

func NewKubectl(namespace string) Kubectl

New Kubectl object

func (Kubectl) Namespace

func (k Kubectl) Namespace() string

Namespace that this Kubectl instance uses

func (Kubectl) Run

func (k Kubectl) Run(args ...string) (string, error)

Run the 'kubectl' CLI with args

type OutputCapture added in v0.16.0

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

func CaptureOutput added in v0.16.0

func CaptureOutput(t *testing.T) OutputCapture

CaptureOutput sets up standard our and standard error to capture any output which

func (OutputCapture) Close added in v0.16.0

func (c OutputCapture) Close() (string, string)

Close return the output collected and restores the original standard out and error streams (i.e. those that were present before the call to CaptureOutput).

Jump to

Keyboard shortcuts

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