{"modulePath":"github.com/AlaudaDevops/pkg","version":"v0.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cluster\n\n## Constants\n\n```go\nconst (\n\tControllerLabel base.TestCaseLabel = \"controller\"\n\tWebhookLabel    base.TestCaseLabel = \"webhook\"\n\tWebServiceLabel base.TestCaseLabel = \"webservice\"\n\tCliLabel        base.TestCaseLabel = \"cli\"\n)\n```\n\n## Functions\n\n```go\nfunc ExpectKubeObject(ctx *TestContext, object ctrlclient.Object, cleanFuncs ...func(object interface{}) interface{}) Assertion\n```\nExpectKubeObject 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.\n\n\tExpectKubeObject(\u0026TestContext{Client: clt, Namespace: \"default\"}, \u0026corev1.ConfigMap{\n\t\tObjectMeta: metav1.ObjectMeta{\n\t\t\tNamespace: \"default\",\n\t\t\tName:      \"config-1\",\n\t\t},\n\t}).Should(testing.DiffEqualTo(\u0026corev1.ConfigMap{\n\t\tObjectMeta: metav1.ObjectMeta{\n\t\t\tNamespace: \"default\",\n\t\t\tName:      \"config-1\",\n\t\t},\n\t\tData: map[string]string{\n\t\t\t\"a\": \"a\",\n\t\t\t\"b\": \"b\",\n\t\t},\n\t}))\n\n```go\nfunc FromSharedScheme(ctx context.Context) *runtime.Scheme\n```\nFromSharedScheme get scheme from context\n\n```go\nfunc GetConfigFromContext(ctx context.Context) interface{}\n```\nGetConfigFromContext get the config information from context\n\n```go\nfunc LoadKubeResourcesToCtx(ctx *TestContext, file string, converts ...testing.ConvertRuntimeObjctToClientObjectFunc) (err error)\n```\nLoadKubeResourcesToCtx 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.\n\n\tLoadKubeResources(ctx, file)// load resource from file and apply to kubernetes with ctx.Namespace and ctx.Client\n\n\t// load resource from file and execute convert if resource type is configmap before apply to kubernetes with ctx.Namespace and ctx.Client\n\n\tLoadKubeResources(ctx, file,func(object runtime.Object) (ctrlclient.Object, error) {\n\t\tconfigmap, ok := object.(*corev1.ConfigMap)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"Unsupported gvk: %s\", object.GetObjectKind().GroupVersionKind())\n\t\t}\n\t\tconfigmap.Namespace = \"default-e2e\"\n\t\tconfigmap.Annotations = map[string]string{\n\t\t\t\"a\": \"1\",\n\t\t}\n\t\treturn configmap, nil\n\t})\n\n```go\nfunc MustLoadKubeResourcesToCtx(ctx *TestContext, file string, converts ...testing.ConvertRuntimeObjctToClientObjectFunc)\n```\nMustLoadKubeResourcesToCtx similar with LoadKubeResources but panic if LoadKubeResources error\n\n```go\nfunc MustRollback(testCtx *TestContext, obj client.Object, opts ...client.DeleteOption)\n```\nMustRollback delete an object and wait for completion\n\n```go\nfunc NewConfigCondition(configName string, obj interface{}) *configCondition\n```\nNewConfigCondition construct an configCondition object \\`obj\\` is a pointer which used to unmarshal configuration to\n\n```go\nfunc NewTestConfigMap(name, namespace string, data map[string]string) *v1.ConfigMap\n```\nNewTestConfigMap helper function for constructing a new configmap\n\n```go\nfunc ReportObjectListWithOptions(ctx *TestContext, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption)\n```\nReportObjectListWithOptions dumps the provided object list into the current Ginkgo spec report if the test case has failed. It allows passing client list options. Example:\n\n\tJustAfteEach(func() {\n\t  ReportObjectListWithOptions(ctx, \u0026corev1.ConfigMapList{}, client.InNamespace(ctx.Namespace))\n\t})\n\nWhen using testing.ListByGVK:\n\n\tJustAfteEach(func() {\n\t  ReportObjectListWithOptions(ctx, ListByGVK(schema.GroupVersionKind{\n\t    Group:   \"alauda.io\",\n\t    Version: \"v1alpha1\",\n\t    Kind:    \"ClusterRuleList\",\n\t  }), client.InNamespace(ctx.Namespace))\n\t})\n\n```go\nfunc ReportObjectsLists(ctx *TestContext, objects ...ctrlclient.ObjectList)\n```\nReportObjectsLists will dump objects into Current Ginkgo Report when test case failed. Example:\n\n\tJustAfteEach(func() {\n\t  ReportObjectsLists(ctx, \u0026corev1.ConfigMapList{}, \u0026corev1.PodList{})\n\t})\n\n```go\nfunc ResourceTopConditionIsReadyEventually(ctx *TestContext, obj client.Object, readyFuncs ...IsReadyCheckFunc) func(g Gomega) error\n```\nResourceTopConditionIsReadyEventually generic function to check if a resource is ready resource type must implement  GetTopLevelCondition() \\*apis.Condition function\n\n```go\nfunc ShareScheme(scheme *runtime.Scheme) base.SharedExtension\n```\nShareScheme to construct extension to share scheme\n\n```go\nfunc SharedClient() base.SharedExtension\n```\nSharedClient to construct extension to share client\n\n```go\nfunc WaitRollback(testCtx *TestContext, obj client.Object)\n```\nWaitRollback Wait for the delete object behavior to complete\n\n```go\nfunc WithSharedScheme(ctx context.Context, scheme *runtime.Scheme) context.Context\n```\nWithSharedScheme wrap scheme into context\n\n## Types\n\n```go\ntype Condition interface {\n\tCondition(testCtx *TestContext) error\n}\n```\n\n```go\nfunc NewNamespaceCondition(ns string) Condition\n```\nNewNamespaceCondition construct a namespace condition\n\n```go\ntype ConditionFunc func(testCtx *TestContext) error\n```\nConditionFunc helper function to wrapping condition\n\n```go\nfunc (c ConditionFunc) Condition(testCtx *TestContext) error\n```\nCondition implement the Condition interface\n\n```go\ntype IsReadyCheckFunc func(g Gomega, obj client.Object) error\n```\nIsReadyCheckFunc additional function to check if object is ready in an Eventually context\n\n\t example:\n\t   ```\n\t   func(g Gomega, obj client.Object) error {\n\t\t  if obj.GetName() == \"\" {\n\t\t\tfmt.Errorf(\"should have a name\")\n\t\t  }\n\t      // or use g.Expect instead\n\t      g.Expect(obj.GetName()).To(Equal(\"\"))\n\t\t  return nil\n\t   }\n\t   ```\n\n```go\ntype NamespaceCondition struct {\n\tNamespace string\n}\n```\nNamespaceCondition generate namespace for testing\n\n```go\nfunc (t *NamespaceCondition) Condition(testCtx *TestContext) error\n```\nCondition 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.\n\n```go\ntype Poller struct {\n\tInterval time.Duration\n\tTimeout  time.Duration\n}\n```\nPoller describe the configuration of Poller Interval: Indicates the inspection interval Timeout: Indicates the maximum time the check will last\n\n```go\nfunc (p Poller) Settings() (interval, timeout time.Duration)\n```\nSettings get the configuration Default values will be used if no custom settings are made\n\n```go\ntype ReconcileCondition struct {\n\t*Poller\n\t// contains filtered or unexported fields\n}\n```\nReconcileCondition check if a controller is available\n\n```go\nfunc NewReconcileCondition(obj client.Object, objCheckFun func(obj client.Object) bool) *ReconcileCondition\n```\nNewReconcileCondition helper function for constructing a \\`ReconcileCondition\\` object\n\n```go\nfunc (n *ReconcileCondition) Condition(testCtx *TestContext) error\n```\nCondition implement the Condition interface Apply an object and wait for reconciliation, then check the status via \\`objCheckFun\\`\n\n```go\nfunc (n *ReconcileCondition) WithPoller(interval, timeout time.Duration) *ReconcileCondition\n```\nWithPoller customize poller settings\n\n```go\ntype ServicePortForward struct {\n\tNamespace         string\n\tServiceName       string\n\tServicePortFilter func(ports []v1.ServicePort) int32\n\t// contains filtered or unexported fields\n}\n```\nServicePortForward describe the configuration of port forwarding\n\n```go\nfunc NewServicePortForward(ns string, serviceName string) *ServicePortForward\n```\nNewServicePortForward construct a new ServicePortForward object\n\n```go\nfunc (s *ServicePortForward) Close()\n```\nClose will stop the forwarder\n\n```go\nfunc (s *ServicePortForward) Forward(testCtx *TestContext) (restyClient *resty.Client, err error)\n```\nForward setting a forwarder\n\n```go\ntype TestCaseBuilder struct {\n\n\t// Conditions condition list which will be checked before test case execution\n\tConditions []Condition\n\n\t// Scope defines what kind of permissions this test case needs\n\tScope TestCaseScope\n\n\t// TestContextOptions used to setup TestContext\n\tTestContextOptions []TestContextOption\n\n\t// Scheme the scheme for initializing the k8s client\n\tScheme *runtime.Scheme\n\n\t// ObjectLists the list of objects to be reported in the test case\n\t// whenever a test case fails\n\tObjectLists []client.ObjectList\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTestCaseBuilder(baseBuilder base.TestCaseBuilder) *TestCaseBuilder\n```\n\n```go\nfunc (b *TestCaseBuilder) Do() bool\n```\nDo build and return the test case\n\n```go\nfunc (b *TestCaseBuilder) DoFunc(f TestSpecFunc) bool\n```\nDoFunc build and return the test case, just like the Do function\n\n```go\nfunc (b *TestCaseBuilder) DoWithContext(ctx context.Context) bool\n```\nDoWithContext runs the test case builder with the given context. It sets up the test context, checks test conditions, adds object reporting, and runs the test spec function if provided.\n\n```go\nfunc (b *TestCaseBuilder) WithClusterScope() *TestCaseBuilder\n```\nWithClusterScope set the scope of the testcase as a cluster scoped\n\n```go\nfunc (b *TestCaseBuilder) WithCondition(funcs ...Condition) *TestCaseBuilder\n```\nWithCondition sets conditions\n\n```go\nfunc (b *TestCaseBuilder) WithFunc(tc TestSpecFunc) *TestCaseBuilder\n```\nWithFunc replaces the function with another given function\n\n```go\nfunc (b *TestCaseBuilder) WithNamespacedScope() *TestCaseBuilder\n```\nWithNamespacedScope set the scope of the testcase as namespaced\n\n```go\nfunc (b *TestCaseBuilder) WithObjectListReport(objectList ...client.ObjectList) *TestCaseBuilder\n```\nWithObjectListReport will add a list of objects to be reported just after each test case if the test case fails. Can be used with testing.ListByGVK() to quickly create an ObjectList. Example: var \\_ = P0Case(\"test case\").\n\n\tCluster().\n\tWithObjectListReport(testing.ListByGVK(schema.GroupVersionKind{\n\t  Group:   \"tekton.dev\",\n\t  Version: \"v1beta1\",\n\t  Kind:    \"PipelineRunList\",\n\t}, \u0026corev1.ConfigMapList{}).DoWithContext(ctx)\n\nNote that multiple ObjectList can be added to the same test case.\n\n```go\nfunc (b *TestCaseBuilder) WithScheme(scheme *runtime.Scheme) *TestCaseBuilder\n```\nWithScheme adds a scheme object to the framework\n\n```go\nfunc (b *TestCaseBuilder) WithTestContextOptions(options ...TestContextOption) *TestCaseBuilder\n```\nWithTestContextOptions sets options of TestContext\n\n```go\ntype TestCaseScope string\n```\nTestCaseScope scope for test case\n\n```go\nconst (\n\t// ClusterScoped cluster test case scope\n\tClusterScoped TestCaseScope = \"Cluster\"\n\t// NamespaceScoped test case scoped for a Namespace\n\tNamespaceScoped TestCaseScope = \"Namespaced\"\n)\n```\n\n```go\ntype TestConfig struct {\n\tNamespace string\n\tName      string\n\t// contains filtered or unexported fields\n}\n```\nTestConfig Provide a unified way to get configuration from configmap\n\n```go\nfunc NewE2EConfig(cmName string) *TestConfig\n```\nNewE2EConfig construct a \\`TestConfig\\` with special configmap name\n\n```go\nfunc (c *TestConfig) GetConfig(ctx context.Context, clt client.Client) (string, error)\n```\nGetConfig get configuration by specified client\n\n```go\ntype TestContext struct {\n\tbase.TestContext\n\n\tConfig    *rest.Config\n\tScheme    *runtime.Scheme\n\tClient    client.Client\n\tNamespace string\n}\n```\nTestContext context for cluster testing\n\n```go\nfunc (ctx *TestContext) GetClient() client.Client\n```\nGetClient returns a client to access kubernetes resources\n\n```go\ntype TestContextOption func(*TestContext)\n```\nTestContextOption options for building TestContext\n\n```go\nfunc NamespaceOption(ns string) TestContextOption\n```\nNamespaceOption customize the namespace name\n\n```go\nfunc NamespacePrefixOption(prefix string) TestContextOption\n```\nNamespacePrefixOption customize the prefix of the namespace name\n\n```go\ntype TestNamespaceCondition struct{}\n```\nTestNamespaceCondition generate namespace for testing\n\n```go\nfunc (t *TestNamespaceCondition) Condition(testCtx *TestContext) error\n```\nCondition 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.\n\n```go\ntype TestSpecFunc func(*TestContext)\n```\n\n","path":"github.com/AlaudaDevops/pkg/testing/framework/cluster","name":"cluster","synopsis":"","isRedistributable":true}
