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
- Variables
- func BrokerCreate(r *KnRunResultCollector, name string)
- func BrokerCreateWithClass(r *KnRunResultCollector, name, class string)
- func BrokerDelete(r *KnRunResultCollector, name string, wait bool)
- func BuildConfigurationSpec(co ...servingtest.ConfigOption) *servingv1.ConfigurationSpec
- func BuildKNExportWithOptions(options ...ExpectedKNExportOption) *clientv1alpha1.Export
- func BuildRevision(name string, options ...servingtest.RevisionOption) *servingv1.Revision
- func BuildRevisionListWithOptions(options ...ExpectedRevisionListOption) *servingv1.RevisionList
- func BuildRevisionSpec(image string) *servingv1.RevisionSpec
- func BuildServiceListWithOptions(options ...ExpectedServiceListOption) *servingv1.ServiceList
- func BuildServiceWithOptions(name string, so ...servingtest.ServiceOption) *servingv1.Service
- func ChannelCreate(r *KnRunResultCollector, cname string, args ...string)
- func ChannelDelete(r *KnRunResultCollector, cname string)
- func ChannelDescribe(r *KnRunResultCollector, cname string, args ...string) string
- func ChannelList(r *KnRunResultCollector, args ...string) string
- func ChannelListTypes(r *KnRunResultCollector, args ...string) string
- func CreateFile(fileName, fileContent, filePath string, fileMode os.FileMode) (string, error)
- func CreateNamespace(namespace string) error
- func CurrentDir(t *testing.T) string
- func DeleteNamespace(namespace string) error
- func EventtypeCreate(r *KnRunResultCollector, name, cetype string)
- func EventtypeCreateWithBrokerSource(r *KnRunResultCollector, name, cetype, broker, source string)
- func EventtypeCreateWithSourceError(r *KnRunResultCollector, name, cetype, source string)
- func EventtypeDelete(r *KnRunResultCollector, name string)
- func EventtypeDescribe(r *KnRunResultCollector, name string)
- func EventtypeList(r *KnRunResultCollector, eventtypes ...string)
- func FindConfigurationGeneration(r *KnRunResultCollector, serviceName string) int
- func FindRevision(r *KnRunResultCollector, serviceName string) string
- func FindRevisionByGeneration(r *KnRunResultCollector, serviceName string, generation int) string
- func GetNextNamespaceId() int
- func GetNextServiceName(base string) string
- func GetResourceFieldsWithJSONPath(t *testing.T, it *KnTest, resource, name, jsonpath string) (string, error)
- func GetServiceFromKNServiceDescribe(r *KnRunResultCollector, serviceName string) servingv1.Service
- func LabelNamespaceForDefaultBroker(r *KnRunResultCollector) error
- func NextNamespace() string
- func RevisionDelete(r *KnRunResultCollector, revName string)
- func RevisionDeleteWithPruneAllOption(r *KnRunResultCollector, revName1, revName2 string)
- func RevisionDeleteWithPruneOption(r *KnRunResultCollector, serviceName, revName string)
- func RevisionDescribe(r *KnRunResultCollector, serviceName string)
- func RevisionDescribeWithPrintFlags(r *KnRunResultCollector, revName string)
- func RevisionListForService(r *KnRunResultCollector, serviceName string)
- func RevisionListOutputName(r *KnRunResultCollector, revisionName string)
- func RevisionListWithService(r *KnRunResultCollector, serviceNames ...string)
- func RevisionMultipleDelete(r *KnRunResultCollector, ...)
- func RunKubectl(namespace string, args ...string) (string, error)
- func ServiceCreate(r *KnRunResultCollector, serviceName string)
- func ServiceCreateNoWait(r *KnRunResultCollector, serviceName string)
- func ServiceDelete(r *KnRunResultCollector, serviceName string)
- func ServiceDescribe(r *KnRunResultCollector, serviceName string)
- func ServiceDescribeWithJSONPath(r *KnRunResultCollector, serviceName, jsonpath string) string
- func ServiceList(r *KnRunResultCollector, serviceName string)
- func ServiceListEmpty(r *KnRunResultCollector)
- func ServiceListOutput(r *KnRunResultCollector, serviceName string)
- func ServiceUpdate(r *KnRunResultCollector, serviceName string, args ...string)
- func ServiceUpdateWithError(r *KnRunResultCollector, serviceName string, args ...string)
- func ServiceWait(r *KnRunResultCollector, serviceName string)
- func SubscriptionCreate(r *KnRunResultCollector, sname string, args ...string)
- func SubscriptionDelete(r *KnRunResultCollector, sname string)
- func SubscriptionDescribe(r *KnRunResultCollector, sname string, args ...string) string
- func SubscriptionList(r *KnRunResultCollector, args ...string) string
- func SubscriptionUpdate(r *KnRunResultCollector, sname string, args ...string)
- func UnlabelNamespaceForDefaultBroker(r *KnRunResultCollector)
- func ValidateServiceResources(r *KnRunResultCollector, serviceName string, ...)
- func WaitForNamespaceCreated(namespace string) error
- func WaitForNamespaceDeleted(namespace string) error
- func WaitForSa(serviceaccount string, namespace string) error
- func WithRevisionAnnotations(annotations map[string]string) servingtest.ServiceOption
- func WithRevisionEnv(evs ...corev1.EnvVar) servingtest.RevisionOption
- func WithRevisionImage(image string) servingtest.RevisionOption
- func WithTrafficSpec(revisions []string, percentages []int, tags []string) servingtest.ServiceOption
- type ClientFlags
- type ExpectedKNExportOption
- type ExpectedRevisionListOption
- type ExpectedServiceListOption
- type Kn
- type KnRunResult
- type KnRunResultCollector
- func (c *KnRunResultCollector) AddDump(kind string, name string, namespace string)
- func (c *KnRunResultCollector) AssertError(result KnRunResult)
- func (c *KnRunResultCollector) AssertNoError(result KnRunResult)
- func (c *KnRunResultCollector) Dump()
- func (c *KnRunResultCollector) DumpIfFailed()
- func (c *KnRunResultCollector) KnTest() *KnTest
- func (c *KnRunResultCollector) T() *testing.T
- type KnTest
- type Kubectl
- type OutputCapture
Constants ¶
const ( FileModeReadWrite = 0666 FileModeExecutable = 0777 )
Variables ¶
var Flags = InitializeFlags()
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 ¶
func BrokerCreate(r *KnRunResultCollector, name string)
BrokerCreate creates a broker with the given name.
func BrokerCreateWithClass ¶
func BrokerCreateWithClass(r *KnRunResultCollector, name, class string)
BrokerCreateWithClass creates a broker with the given name and class.
func BrokerDelete ¶
func BrokerDelete(r *KnRunResultCollector, name string, wait bool)
BrokerDelete deletes a broker with the given name.
func BuildConfigurationSpec ¶
func BuildConfigurationSpec(co ...servingtest.ConfigOption) *servingv1.ConfigurationSpec
BuildConfigurationSpec builds servingv1.ConfigurationSpec with the options provided
func BuildKNExportWithOptions ¶
func BuildKNExportWithOptions(options ...ExpectedKNExportOption) *clientv1alpha1.Export
BuildKNExportWithOptions returns Export object with the options provided
func BuildRevision ¶
func BuildRevision(name string, options ...servingtest.RevisionOption) *servingv1.Revision
BuildRevision returns Revision object with the options provided
func BuildRevisionListWithOptions ¶
func BuildRevisionListWithOptions(options ...ExpectedRevisionListOption) *servingv1.RevisionList
BuildRevisionListWithOptions returns RevisionList with options provided
func BuildRevisionSpec ¶
func BuildRevisionSpec(image string) *servingv1.RevisionSpec
BuildRevisionSpec for provided image
func BuildServiceListWithOptions ¶
func BuildServiceListWithOptions(options ...ExpectedServiceListOption) *servingv1.ServiceList
BuildServiceListWithOptions returns ServiceList with options provided
func BuildServiceWithOptions ¶
func BuildServiceWithOptions(name string, so ...servingtest.ServiceOption) *servingv1.Service
BuildServiceWithOptions returns ksvc with options provided
func ChannelCreate ¶
func ChannelCreate(r *KnRunResultCollector, cname string, args ...string)
func ChannelDelete ¶
func ChannelDelete(r *KnRunResultCollector, cname string)
func ChannelDescribe ¶
func ChannelDescribe(r *KnRunResultCollector, cname string, args ...string) string
func ChannelList ¶
func ChannelList(r *KnRunResultCollector, args ...string) string
func ChannelListTypes ¶
func ChannelListTypes(r *KnRunResultCollector, args ...string) string
ChannelListTypes return available channel types
func CreateFile ¶
CreateFile creates a file with given name, content, path, fileMode and returns absolute filepath and error if any
func CreateNamespace ¶
CreateNamespace creates and tests a namespace creation invoking kubectl
func CurrentDir ¶
func DeleteNamespace ¶
DeleteNamespace deletes and tests a namespace deletion invoking kubectl
func EventtypeCreate ¶
func EventtypeCreate(r *KnRunResultCollector, name, cetype string)
EventtypeCreate creates an eventtype with the given name.
func EventtypeCreateWithBrokerSource ¶
func EventtypeCreateWithBrokerSource(r *KnRunResultCollector, name, cetype, broker, source string)
func EventtypeCreateWithSourceError ¶
func EventtypeCreateWithSourceError(r *KnRunResultCollector, name, cetype, source string)
func EventtypeDelete ¶
func EventtypeDelete(r *KnRunResultCollector, name string)
EventtypeDelete deletes an eventtype with the given name.
func EventtypeDescribe ¶
func EventtypeDescribe(r *KnRunResultCollector, name string)
EventtypeDescribe describes an eventtype with the given name.
func EventtypeList ¶
func EventtypeList(r *KnRunResultCollector, eventtypes ...string)
EventtypeList verifies listing eventtypes in the given namespace
func FindConfigurationGeneration ¶
func FindConfigurationGeneration(r *KnRunResultCollector, serviceName string) int
FindConfigurationGeneration returns the configuration generation number of given service
func FindRevision ¶
func FindRevision(r *KnRunResultCollector, serviceName string) string
FindRevision returns a revision name (at index 0) for given service
func FindRevisionByGeneration ¶
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 ¶
GetNextServiceName return the name for the next namespace
func GetResourceFieldsWithJSONPath ¶
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 ¶
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 ¶
func LabelNamespaceForDefaultBroker(r *KnRunResultCollector) error
LabelNamespaceForDefaultBroker adds label 'knative-eventing-injection=enabled' to the configured namespace
func RevisionDelete ¶
func RevisionDelete(r *KnRunResultCollector, revName string)
RevisionDelete verifies deleting given revision in sync mode
func RevisionDeleteWithPruneAllOption ¶
func RevisionDeleteWithPruneAllOption(r *KnRunResultCollector, revName1, revName2 string)
RevisionDeleteWithPruneAllOption verifies removeing all unreferenced revision in sync mode
func RevisionDeleteWithPruneOption ¶
func RevisionDeleteWithPruneOption(r *KnRunResultCollector, serviceName, revName string)
RevisionDeleteWithPruneOption verifies removeing all unreferenced revisions for a given service in sync mode
func RevisionDescribe ¶
func RevisionDescribe(r *KnRunResultCollector, serviceName string)
RevisionDescribe verifies revision describe output for given service's revision
func RevisionDescribeWithPrintFlags ¶
func RevisionDescribeWithPrintFlags(r *KnRunResultCollector, revName string)
RevisionDescribeWithPrintFlags verifies describing given revision using print flag '--output=name'
func RevisionListForService ¶
func RevisionListForService(r *KnRunResultCollector, serviceName string)
RevisionListForService list revisions of given service and verifies if their status is True
func RevisionListOutputName ¶
func RevisionListOutputName(r *KnRunResultCollector, revisionName string)
RevisionListOutputName verifies listing given revision using print flag '--output name'
func RevisionListWithService ¶
func RevisionListWithService(r *KnRunResultCollector, serviceNames ...string)
RevisionListWithService verifies listing revisions per service from each given service names
func RevisionMultipleDelete ¶
func RevisionMultipleDelete(r *KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string)
RevisionMultipleDelete verifies deleting multiple revisions
func RunKubectl ¶
RunKubectl runs "kubectl" in a given namespace
func ServiceCreate ¶
func ServiceCreate(r *KnRunResultCollector, serviceName string)
ServiceCreate verifies given service creation in sync mode and also verifies output
func ServiceCreateNoWait ¶
func ServiceCreateNoWait(r *KnRunResultCollector, serviceName string)
ServiceCreate verifies given service creation async mode and also verifies output
func ServiceDelete ¶
func ServiceDelete(r *KnRunResultCollector, serviceName string)
ServiceDelete verifies service deletion in sync mode
func ServiceDescribe ¶
func ServiceDescribe(r *KnRunResultCollector, serviceName string)
ServiceDescribe describes given service and verifies the keys in the output
func ServiceDescribeWithJSONPath ¶
func ServiceDescribeWithJSONPath(r *KnRunResultCollector, serviceName, jsonpath string) string
ServiceDescribeWithJSONPath returns output of given JSON path by describing the service
func ServiceList ¶
func ServiceList(r *KnRunResultCollector, serviceName string)
ServiceList verifies if given service exists
func ServiceListEmpty ¶
func ServiceListEmpty(r *KnRunResultCollector)
ServiceListEmpty verifies that there are no services present
func ServiceListOutput ¶
func ServiceListOutput(r *KnRunResultCollector, serviceName string)
ServiceListOutput verifies listing given service using '--output name' flag
func ServiceUpdate ¶
func ServiceUpdate(r *KnRunResultCollector, serviceName string, args ...string)
ServiceUpdate verifies service update operation with given arguments in sync mode
func ServiceUpdateWithError ¶
func ServiceUpdateWithError(r *KnRunResultCollector, serviceName string, args ...string)
ServiceUpdateWithError verifies service update operation with given arguments in sync mode when expecting an error
func ServiceWait ¶
func ServiceWait(r *KnRunResultCollector, serviceName string)
ServiceWait waits for service to be ready and also verifies output
func SubscriptionCreate ¶
func SubscriptionCreate(r *KnRunResultCollector, sname string, args ...string)
func SubscriptionDelete ¶
func SubscriptionDelete(r *KnRunResultCollector, sname string)
func SubscriptionDescribe ¶
func SubscriptionDescribe(r *KnRunResultCollector, sname string, args ...string) string
func SubscriptionList ¶
func SubscriptionList(r *KnRunResultCollector, args ...string) string
func SubscriptionUpdate ¶
func SubscriptionUpdate(r *KnRunResultCollector, sname string, args ...string)
func UnlabelNamespaceForDefaultBroker ¶
func UnlabelNamespaceForDefaultBroker(r *KnRunResultCollector)
UnlabelNamespaceForDefaultBroker removes label 'knative-eventing-injection=enabled' from the configured namespace
func ValidateServiceResources ¶
func ValidateServiceResources(r *KnRunResultCollector, serviceName string, requestsMemory, requestsCPU, limitsMemory, limitsCPU string)
ValidateServiceResources validates cpu and mem resources
func WaitForNamespaceCreated ¶
WaitForNamespaceCreated wait until namespace is created
func WaitForNamespaceDeleted ¶
WaitForNamespaceDeleted wait until namespace is deleted
func WithRevisionAnnotations ¶
func WithRevisionAnnotations(annotations map[string]string) servingtest.ServiceOption
WithRevisionAnnotations adds annotation to revision spec in ksvc
func WithRevisionEnv ¶
func WithRevisionEnv(evs ...corev1.EnvVar) servingtest.RevisionOption
WithRevisionEnv adds env variable to Revision object
func WithRevisionImage ¶
func WithRevisionImage(image string) servingtest.RevisionOption
WithRevisionImage adds revision image to Revision object
func WithTrafficSpec ¶
func WithTrafficSpec(revisions []string, percentages []int, tags []string) servingtest.ServiceOption
WithTrafficSpec adds route to ksvc
Types ¶
type ClientFlags ¶
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 ¶
type ExpectedKNExportOption func(*clientv1alpha1.Export)
ExpectedKNExportOption enables further configuration of a Export.
func WithKNRevision ¶
func WithKNRevision(rev servingv1.Revision) ExpectedKNExportOption
WithKNRevision appends Revision object RevisionList to Kn Export
type ExpectedRevisionListOption ¶
type ExpectedRevisionListOption func(*servingv1.RevisionList)
ExpectedRevisionListOption enables further configuration of a RevisionList.
func WithRevision ¶
func WithRevision(rev servingv1.Revision) ExpectedRevisionListOption
WithRevision appends Revision object to RevisionList
type ExpectedServiceListOption ¶
type ExpectedServiceListOption func(*servingv1.ServiceList)
ExpectedServiceListOption enables further configuration of a ServiceList.
func WithService ¶
func WithService(svc *servingv1.Service) ExpectedServiceListOption
WithService appends the given service to ServiceList
type Kn ¶
type Kn struct {
// contains filtered or unexported fields
}
Kn type
func (Kn) RunNoNamespace ¶
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 ¶
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 ¶
func (c *KnRunResultCollector) KnTest() *KnTest
KnTest returns the KnTest object
func (*KnRunResultCollector) T ¶
func (c *KnRunResultCollector) T() *testing.T
T returns the *testing.T object
type Kubectl ¶
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl type
type OutputCapture ¶
type OutputCapture struct {
// contains filtered or unexported fields
}
func CaptureOutput ¶
func CaptureOutput(t *testing.T) OutputCapture
CaptureOutput sets up standard our and standard error to capture any output which
func (OutputCapture) Close ¶
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).