testutils

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package testutils provides test utility functions for the CLI package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTestKubeconfig

func CreateTestKubeconfig(t *testing.T, namespace string) string

CreateTestKubeconfig creates a temporary kubeconfig file for testing If namespace is empty, no namespace is set in the context

func CreateTestRecord added in v0.17.0

func CreateTestRecord(clock clockwork.Clock, name, uid, namespace string, startTime, endTime *time.Time, conditionStatus string, labels map[string]string) *pb.Record

CreateTestRecord creates a test record with all possible options Use empty string for namespace to use default, nil for labels to omit them

func ExecuteCommand added in v0.17.0

func ExecuteCommand(c *cobra.Command, args ...string) (string, error)

ExecuteCommand executes the root command passing the args and returns the output as a string and error

func MockRESTClientFromRecords added in v0.17.0

func MockRESTClientFromRecords(records []*pb.Record) (*client.RESTClient, error)

MockRESTClientFromRecords creates a mock REST client with comprehensive filtering support

func ReadKubeconfigExtension

func ReadKubeconfigExtension(t *testing.T, kubeconfigPath, extensionName string, target interface{}) (bool, error)

ReadKubeconfigExtension reads and unmarshals a kubeconfig extension into the provided target The target parameter should be a pointer to the struct you want to unmarshal into Returns true if the extension was found and unmarshaled successfully, false if not found

func ReadKubeconfigExtensionRaw

func ReadKubeconfigExtensionRaw(t *testing.T, kubeconfigPath, extensionName string) ([]byte, error)

ReadKubeconfigExtensionRaw reads the tekton-results extension from a kubeconfig file as raw data This avoids import cycles by not depending on config package types

func TimePtr added in v0.17.0

func TimePtr(t time.Time) *time.Time

TimePtr converts time.Time to *time.Time

func UpdateKubeconfigNamespace added in v0.17.0

func UpdateKubeconfigNamespace(t *testing.T, kubeconfigPath, newNamespace string)

UpdateKubeconfigNamespace updates the namespace of the current context in a kubeconfig file

Types

type Params added in v0.17.0

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

Params implements common.Params interface for testing This allows injecting fake/mock clients during tests

func NewParams added in v0.17.0

func NewParams() *Params

NewParams creates a new test Params with sensible defaults

func (*Params) APIPath added in v0.17.0

func (p *Params) APIPath() string

APIPath returns the API path

func (*Params) Host added in v0.17.0

func (p *Params) Host() string

Host returns the API host

func (*Params) KubeConfigPath added in v0.17.0

func (p *Params) KubeConfigPath() string

KubeConfigPath returns the kubeconfig file path

func (*Params) KubeContext added in v0.17.0

func (p *Params) KubeContext() string

KubeContext returns the kubernetes context

func (*Params) Namespace added in v0.17.0

func (p *Params) Namespace() string

Namespace returns the kubernetes namespace

func (*Params) RESTClient added in v0.17.0

func (p *Params) RESTClient() *client.RESTClient

RESTClient returns the injected REST client for testing

func (*Params) SetAPIPath added in v0.17.0

func (p *Params) SetAPIPath(path string)

SetAPIPath sets the API path

func (*Params) SetHost added in v0.17.0

func (p *Params) SetHost(host string)

SetHost sets the API host

func (*Params) SetKubeConfigPath added in v0.17.0

func (p *Params) SetKubeConfigPath(path string)

SetKubeConfigPath sets the kubeconfig file path

func (*Params) SetKubeContext added in v0.17.0

func (p *Params) SetKubeContext(context string)

SetKubeContext sets the kubernetes context

func (*Params) SetNamespace added in v0.17.0

func (p *Params) SetNamespace(ns string)

SetNamespace sets the kubernetes namespace, preserving default if empty

func (*Params) SetRESTClient added in v0.17.0

func (p *Params) SetRESTClient(client *client.RESTClient)

SetRESTClient injects a REST client for testing purposes

func (*Params) SetSkipTLSVerify added in v0.17.0

func (p *Params) SetSkipTLSVerify(skip bool)

SetSkipTLSVerify sets whether to skip TLS verification

func (*Params) SetToken added in v0.17.0

func (p *Params) SetToken(token string)

SetToken sets the authentication token

func (*Params) SkipTLSVerify added in v0.17.0

func (p *Params) SkipTLSVerify() bool

SkipTLSVerify returns whether to skip TLS verification

func (*Params) Token added in v0.17.0

func (p *Params) Token() string

Token returns the authentication token

Jump to

Keyboard shortcuts

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