common

package
v0.0.0-...-989fbaf Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var YamlStringTransformer = cmp.Transformer("YamlLines", func(s YamlString) []string {

	lines := strings.Split(string(s), "\n")

	// Remove any empty lines from the start and end.
	var start, end int
	for i := range lines {
		if lines[i] != "" {
			start = i
			break
		}
	}
	for i := len(lines) - 1; i >= 0; i-- {
		if lines[i] != "" {
			end = i
			break
		}
	}
	return lines[start : end+1]
})

YamlStringTransformer transforms a YamlString into a slice of strings by splitting on each new line. This allows the diffing function (used in tests) to compare each line independently. The result is that the diff output marks each line where a diff was observed.

Functions

func MapToValues

func MapToValues[K comparable, V any](obj map[K]V) []V

func NamespaceForTest

func NamespaceForTest(name string) *corev1.Namespace

func PtrTo

func PtrTo[T any](a T) *T

Types

type JSONString

type JSONString string

func (JSONString) CmpDiff

func (src JSONString) CmpDiff(tgt JSONString) (diff string, err error)

type K8sClients

type K8sClients struct {
	Client          client.Client
	DC              dynamic.Interface
	DiscoveryClient discovery.DiscoveryInterface
}

func MustClientsForTest

func MustClientsForTest(t *testing.T, initRuntimeObjects ...runtime.Object) *K8sClients

func NewK8sClients

func NewK8sClients(kubeconfig string) (*K8sClients, error)

type ObjRef

type ObjRef struct {
	Group     string `json:",omitempty"`
	Kind      string `json:",omitempty"`
	Name      string `json:",omitempty"`
	Namespace string `json:",omitempty"`
}

ObjRef defines a reference to a Kubernetes resource, using plain strings for easier comparison.

type YamlString

type YamlString string

YamlString defines a custom type for wrapping yaml texts. It makes use of YamlStringTransformer to generate slightly better diffing output from cmp.Diff() for multi-line yaml texts.

Jump to

Keyboard shortcuts

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