Documentation ¶
Index ¶
- Constants
- func ConvertToAuthSecret(auth client.Auth) (secret corev1.Secret)
- func ExpectKubeObject(ctx *TestContext, object ctrlclient.Object, ...) Assertion
- func FromSharedScheme(ctx context.Context) *runtime.Scheme
- func GetConfigFromContext(ctx context.Context) interface{}
- func GetPluginAddress(client *resty.Client, plugin client.Interface) (address *duckv1.Addressable, err error)
- func LoadKubeResourcesToCtx(ctx *TestContext, file string, ...) (err error)
- func MustGetPluginAddress(client *resty.Client, plugin client.Interface) (address *duckv1.Addressable)
- func MustLoadKubeResourcesToCtx(ctx *TestContext, file string, ...)
- func MustRollback(testCtx *TestContext, obj client.Object, opts ...client.DeleteOption)
- func NewConfigCondition(configName string, obj interface{}) *configCondition
- func NewTestConfigMap(name, namespace string, data map[string]string) *v1.ConfigMap
- func PluginService(ctx context.Context, clt client.Client, name string) (*corev1.Service, error)
- func RequestWrapAuthMeta(req *resty.Request, auth client.Auth, meta client.Meta) *resty.Request
- func ResourceTopConditionIsReadyEventually(ctx *TestContext, obj client.Object, readyFuncs ...IsReadyCheckFunc) func(g Gomega) error
- func ShareScheme(scheme *runtime.Scheme) base.SharedExtension
- func SharedClient() base.SharedExtension
- func WaitRollback(testCtx *TestContext, obj client.Object)
- func WithSharedScheme(ctx context.Context, scheme *runtime.Scheme) context.Context
- type Condition
- type ConditionFunc
- type IsReadyCheckFunc
- type NamespaceCondition
- type Poller
- type ReconcileCondition
- type ServicePortForward
- type TestCaseBuilder
- func (b *TestCaseBuilder) Do() bool
- func (b *TestCaseBuilder) DoFunc(f TestSpecFunc) bool
- func (b *TestCaseBuilder) DoWithContext(ctx context.Context) bool
- func (b *TestCaseBuilder) WithClusterScope() *TestCaseBuilder
- func (b *TestCaseBuilder) WithCondition(funcs ...Condition) *TestCaseBuilder
- func (b *TestCaseBuilder) WithFunc(tc TestSpecFunc) *TestCaseBuilder
- func (b *TestCaseBuilder) WithNamespacedScope() *TestCaseBuilder
- func (b *TestCaseBuilder) WithScheme(scheme *runtime.Scheme) *TestCaseBuilder
- func (b *TestCaseBuilder) WithTestContextOptions(options ...TestContextOption) *TestCaseBuilder
- type TestCaseScope
- type TestConfig
- type TestContext
- type TestContextOption
- type TestNamespaceCondition
- type TestSpecFunc
Constants ¶
const ( ControllerLabel base.TestCaseLabel = "controller" WebhookLabel base.TestCaseLabel = "webhook" WebServiceLabel base.TestCaseLabel = "webservice" CliLabel base.TestCaseLabel = "cli" )
Variables ¶
This section is empty.
Functions ¶
func ConvertToAuthSecret ¶
ConvertToAuthSecret convert auth
func ExpectKubeObject ¶ added in v0.11.0
func ExpectKubeObject(ctx *TestContext, object ctrlclient.Object, cleanFuncs ...func(object interface{}) interface{}) Assertion
ExpectKubeObject expect kubernetes resource exists by object.name and object.namespace, clean some fields in object and return gomega.Expect for this object. the param object should contains Namespace and name. you can use cleanFuncs to clean some fileds for object that load from kubernetes eg.
ExpectKubeObject(&TestContext{Client: clt, Namespace: "default"}, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "config-1", }, }).Should(testing.DiffEqualTo(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "config-1", }, Data: map[string]string{ "a": "a", "b": "b", }, }))
func FromSharedScheme ¶
FromSharedScheme get scheme from context
func GetConfigFromContext ¶
GetConfigFromContext get the config information from context
func GetPluginAddress ¶
func GetPluginAddress(client *resty.Client, plugin client.Interface) (address *duckv1.Addressable, err error)
GetPluginAddress get the base url of the plugin
func LoadKubeResourcesToCtx ¶ added in v0.11.0
func LoadKubeResourcesToCtx(ctx *TestContext, file string, converts ...testing.ConvertRuntimeObjctToClientObjectFunc) (err error)
LoadKubeResourcesToCtx will load kubernetes resources from file it will use client in ctx and set namespace as ctx.Namespace if namespace is empty in file if you set namespace in file, it will just use it and ignore ctx.Namespace you can set converts to change some extra fields before create in kubernetes but you must pay attention to that when you set more than one converts: just one converts will be executed when match if you set converts , you should set namespace to ctx.Namespace explicitly eg.
LoadKubeResources(ctx, file)// load resource from file and apply to kubernetes with ctx.Namespace and ctx.Client // load resource from file and execute convert if resource type is configmap before apply to kubernetes with ctx.Namespace and ctx.Client LoadKubeResources(ctx, file,func(object runtime.Object) (ctrlclient.Object, error) { configmap, ok := object.(*corev1.ConfigMap) if !ok { return nil, fmt.Errorf("Unsupported gvk: %s", object.GetObjectKind().GroupVersionKind()) } configmap.Namespace = "default-e2e" configmap.Annotations = map[string]string{ "a": "1", } return configmap, nil })
func MustGetPluginAddress ¶
func MustGetPluginAddress(client *resty.Client, plugin client.Interface) (address *duckv1.Addressable)
MustGetPluginAddress get the base url or panics if the parse fails.
func MustLoadKubeResourcesToCtx ¶ added in v0.11.0
func MustLoadKubeResourcesToCtx(ctx *TestContext, file string, converts ...testing.ConvertRuntimeObjctToClientObjectFunc)
MustLoadKubeResourcesToCtx similar with LoadKubeResources but panic if LoadKubeResources error
func MustRollback ¶
func MustRollback(testCtx *TestContext, obj client.Object, opts ...client.DeleteOption)
MustRollback delete an object and wait for completion
func NewConfigCondition ¶
func NewConfigCondition(configName string, obj interface{}) *configCondition
NewConfigCondition construct an configCondition object `obj` is a pointer which used to unmarshal configuration to
func NewTestConfigMap ¶
NewTestConfigMap helper function for constructing a new configmap
func PluginService ¶
PluginService Get plugin service by plugin name
func RequestWrapAuthMeta ¶
RequestWrapAuthMeta wrap auth and meta information into http request
func ResourceTopConditionIsReadyEventually ¶
func ResourceTopConditionIsReadyEventually(ctx *TestContext, obj client.Object, readyFuncs ...IsReadyCheckFunc) func(g Gomega) error
ResourceTopConditionIsReadyEventually generic function to check if a resource is ready resource type must implement GetTopLevelCondition() *apis.Condition function
func ShareScheme ¶
func ShareScheme(scheme *runtime.Scheme) base.SharedExtension
ShareScheme to construct extension to share scheme
func SharedClient ¶ added in v0.11.0
func SharedClient() base.SharedExtension
SharedClient to construct extension to share client
func WaitRollback ¶
func WaitRollback(testCtx *TestContext, obj client.Object)
WaitRollback Wait for the delete object behavior to complete
Types ¶
type Condition ¶
type Condition interface {
Condition(testCtx *TestContext) error
}
func NewNamespaceCondition ¶
NewNamespaceCondition construct a namespace condition
type ConditionFunc ¶
type ConditionFunc func(testCtx *TestContext) error
ConditionFunc helper function to wrapping condition
func (ConditionFunc) Condition ¶
func (c ConditionFunc) Condition(testCtx *TestContext) error
Condition implement the Condition interface
type IsReadyCheckFunc ¶
IsReadyCheckFunc additional function to check if object is ready in an Eventually context
example: ``` func(g Gomega, obj client.Object) error { if obj.GetName() == "" { fmt.Errorf("should have a name") } // or use g.Expect instead g.Expect(obj.GetName()).To(Equal("")) return nil } ```
type NamespaceCondition ¶
type NamespaceCondition struct {
Namespace string
}
NamespaceCondition generate namespace for testing
func (*NamespaceCondition) Condition ¶
func (t *NamespaceCondition) Condition(testCtx *TestContext) error
Condition implement the Condition interface Delete the namespace when it already exists, then create a new one. After the testing is completed, delete the namespace as well.
type Poller ¶
Poller describe the configuration of Poller Interval: Indicates the inspection interval Timeout: Indicates the maximum time the check will last
type ReconcileCondition ¶
type ReconcileCondition struct { *Poller // contains filtered or unexported fields }
ReconcileCondition check if a controller is available
func NewReconcileCondition ¶
func NewReconcileCondition(obj client.Object, objCheckFun func(obj client.Object) bool) *ReconcileCondition
NewReconcileCondition helper function for constructing a `ReconcileCondition` object
func (*ReconcileCondition) Condition ¶
func (n *ReconcileCondition) Condition(testCtx *TestContext) error
Condition implement the Condition interface Apply an object and wait for reconciliation, then check the status via `objCheckFun`
func (*ReconcileCondition) WithPoller ¶
func (n *ReconcileCondition) WithPoller(interval, timeout time.Duration) *ReconcileCondition
WithPoller customize poller settings
type ServicePortForward ¶
type ServicePortForward struct { Namespace string ServiceName string ServicePortFilter func(ports []v1.ServicePort) int32 // contains filtered or unexported fields }
ServicePortForward describe the configuration of port forwarding
func NewServicePortForward ¶
func NewServicePortForward(ns string, serviceName string) *ServicePortForward
NewServicePortForward construct a new ServicePortForward object
func (*ServicePortForward) Close ¶
func (s *ServicePortForward) Close()
Close will stop the forwarder
func (*ServicePortForward) Forward ¶
func (s *ServicePortForward) Forward(testCtx *TestContext) (restyClient *resty.Client, err error)
Forward setting a forwarder
type TestCaseBuilder ¶
type TestCaseBuilder struct { // Conditions condition list which will be checked before test case execution Conditions []Condition // Scope defines what kind of permissions this test case needs Scope TestCaseScope // TestContextOptions used to setup TestContext TestContextOptions []TestContextOption // Scheme the scheme for initializing the k8s client Scheme *runtime.Scheme // contains filtered or unexported fields }
func NewTestCaseBuilder ¶
func NewTestCaseBuilder(baseBuilder base.TestCaseBuilder) *TestCaseBuilder
func (*TestCaseBuilder) DoFunc ¶
func (b *TestCaseBuilder) DoFunc(f TestSpecFunc) bool
DoFunc build and return the test case, just like the Do function
func (*TestCaseBuilder) DoWithContext ¶ added in v0.11.0
func (b *TestCaseBuilder) DoWithContext(ctx context.Context) bool
func (*TestCaseBuilder) WithClusterScope ¶
func (b *TestCaseBuilder) WithClusterScope() *TestCaseBuilder
WithClusterScope set the scope of the testcase as a cluster scoped
func (*TestCaseBuilder) WithCondition ¶
func (b *TestCaseBuilder) WithCondition(funcs ...Condition) *TestCaseBuilder
WithCondition sets conditions
func (*TestCaseBuilder) WithFunc ¶
func (b *TestCaseBuilder) WithFunc(tc TestSpecFunc) *TestCaseBuilder
WithFunc replaces the function with another given function
func (*TestCaseBuilder) WithNamespacedScope ¶
func (b *TestCaseBuilder) WithNamespacedScope() *TestCaseBuilder
WithNamespacedScope set the scope of the testcase as namespaced
func (*TestCaseBuilder) WithScheme ¶
func (b *TestCaseBuilder) WithScheme(scheme *runtime.Scheme) *TestCaseBuilder
WithScheme adds a scheme object to the framework
func (*TestCaseBuilder) WithTestContextOptions ¶
func (b *TestCaseBuilder) WithTestContextOptions(options ...TestContextOption) *TestCaseBuilder
WithTestContextOptions sets options of TestContext
type TestCaseScope ¶
type TestCaseScope string
TestCaseScope scope for test case
const ( // ClusterScoped cluster test case scope ClusterScoped TestCaseScope = "Cluster" // NamespaceScoped test case scoped for a Namespace NamespaceScoped TestCaseScope = "Namespaced" )
type TestConfig ¶
TestConfig Provide a unified way to get configuration from configmap
func NewE2EConfig ¶
func NewE2EConfig(cmName string) *TestConfig
NewE2EConfig construct a `TestConfig` with special configmap name
type TestContext ¶
type TestContext struct { base.TestContext Config *rest.Config Scheme *runtime.Scheme Client client.Client Namespace string MultiClusterClient multicluster.Interface }
TestContext context for cluster testing
func (*TestContext) GetClient ¶ added in v0.11.0
func (ctx *TestContext) GetClient() client.Client
GetClient returns a client to access kubernetes resources
type TestContextOption ¶
type TestContextOption func(*TestContext)
TestContextOption options for building TestContext
func NamespaceOption ¶
func NamespaceOption(ns string) TestContextOption
NamespaceOption customize the namespace name
func NamespacePrefixOption ¶
func NamespacePrefixOption(prefix string) TestContextOption
NamespacePrefixOption customize the prefix of the namespace name
type TestNamespaceCondition ¶
type TestNamespaceCondition struct{}
TestNamespaceCondition generate namespace for testing
func (*TestNamespaceCondition) Condition ¶
func (t *TestNamespaceCondition) Condition(testCtx *TestContext) error
Condition implement the Condition interface Delete the namespace when it already exists, then create a new one. After the testing is completed, delete the namespace as well.
type TestSpecFunc ¶
type TestSpecFunc func(*TestContext)