test

package
v0.0.0-...-acb352a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSuccessTimeout for operations that are expected to succeed.
	DefaultSuccessTimeout = 5 * time.Minute

	// DefaultFailureTimeout for operations that are *expected* to time out.
	//
	// The timeout is short because timeouts are *never* a reliable way to
	// determine that something does not happen. At best such a test *might* catch
	// the problem. It is better than nothing, but not by much. Definitely not
	// worth delaying the entire test suite for.
	//
	// Ideally tests for non-happening should have a positive wait with
	// DefaultSuccessTimeout for something that we know *does* happen, and that we
	// know never happens *before* the thing we don't expect to happen.  Then look
	// for positive proof that the thing didn't happen. A negative timeout result
	// never proves that the thing won't happen in 1 more millisecond.
	//
	DefaultFailureTimeout = 1 * time.Second

	OpenshiftOperatorsRedhatNS = "openshift-operators-redhat"
)

Variables

View Source
var JSONString = utilsjson.MustMarshal

JSONString returns a JSON string of a value, or an error message.

Functions

func Escapelines

func Escapelines(logline string) string

func FailureTimeout

func FailureTimeout() time.Duration

func GinkgoCurrentTest

func GinkgoCurrentTest() (g ginkgo.GinkgoTestDescription, ok bool)

GinkgoCurrentTest tries to get the current Ginkgo test description. Returns true if successful, false if not in a ginkgo test.

func GitRoot

func GitRoot(paths ...string) string

GitRoot joins paths to the root of the git repository. Panics if current directory is not inside a git repository.

func HTMLBodyText

func HTMLBodyText(r io.Reader) ([]byte, error)

HTMLBodyText extracts text from the <body> of a HTML document. Useful for test error messages, not for much else.

func HTTPError

func HTTPError(resp *http.Response) error

HTTPError returns an error constructed from resp.Body if resp.Status is not 2xx. Returns nil otherwise.

func JSONLine

func JSONLine(v interface{}) string

JSONLine returns a one-line JSON string, or an error message.

func LogBeginEnd

func LogBeginEnd(l logr.Logger, msg string, errp *error, kv ...interface{}) func()

LogBeginEnd logs an l.V(3) begin message, returns func to log an lV(2) end message. End message includes elapsed time and error errp and *errp are non nil. Use it to log the time spent in a function like this:

func blah() (err error) {
    defer LogBeginEnd(log, "eating", &err)()
    ...

Note the trailing () - this calls LogBeginEnd() and defers calling the func it returns.

func MapIndices

func MapIndices(m interface{}, index ...interface{}) (value interface{})

MapIndices indexes into a multi-level map[string]interface{} unmarshalled from JSON. Result is like `m[index1][index2]..` Returns nil if an index is not found.

func Must

func Must(err error)

Must panics if err is not nil.

func MustUnmarshal

func MustUnmarshal(s string, v interface{})

MustUnmarshal unmarshals JSON or YAML into a value, panic on error.

func SuccessTimeout

func SuccessTimeout() time.Duration

func TrimLines

func TrimLines(lines string) string

TrimLines trims leading and trailing whitespace from every line in lines. Useful for comparing configuration snippets with varied indenting.

func UniqueName

func UniqueName(prefix string) string

UniqueName generates a unique DNS label string starting with prefix. Illegal character sequences in prefix are replaced with "-". Suffix sorts by time of creation if < 12h apart.

func UniqueNameForTest

func UniqueNameForTest() string

UniqueNameForTest generates a unique name for a test.

func Unmarshal

func Unmarshal(s string, v interface{}) error

Unmarshal JSON or YAML string into a value according to k8s rules. Uses sigs.k8s.io/yaml.

func Writer

func Writer() io.Writer

Writer for log or error output from tests when there is nowhere better to send it. Returns GinkgoWriter if available, os.Stderr otherwise.

func YAMLString

func YAMLString(v interface{}) string

YAMLString returns a YAML string of a value, using the sigs.k8s.io/yaml package, or an error message.

Types

type FailGroup

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

A FailGroup is a collection of goroutines running concurrently as part of a Ginkgo test. The goroutines may exit by calling ginkgo.Fail(), for example by using Expect(). they may also return an error.

This is essentially errgroup.Group extended to recover ginkgo.Fail() correctly.

func (*FailGroup) Go

func (g *FailGroup) Go(f func())

Go runs f concurrently and recovers from ginkgo.Fail() panics.

func (*FailGroup) Wait

func (g *FailGroup) Wait()

Wait waits for all goroutines to exit.

It calls ginkgo.Fail() if any goroutine returned an error or called ginkgo.Fail().

Directories

Path Synopsis
package client provides a client for tests.
package client provides a client for tests.
e2e
flowcontrol
End-to-End Tests for Log Flow Control LOG-1043: Log Flow Control API Enhancement
End-to-End Tests for Log Flow Control LOG-1043: Log Flow Control API Enhancement
e2e
flowcontrol
Functional Tests for Log Flow Control
Functional Tests for Log Flow Control
cmd
fluentd
package fluentd provides a fluentd receiver for use in e2e forwarding tests.
package fluentd provides a fluentd receiver for use in e2e forwarding tests.
oc
package runtime provides conveniences based on "k8s.io/apimachinery/pkg/runtime"
package runtime provides conveniences based on "k8s.io/apimachinery/pkg/runtime"

Jump to

Keyboard shortcuts

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