testutil

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const VenConnRBAC = `` /* 1584-byte string literal not displayed */

Generated using:

helm template ./deploy/charts/venafi-kubernetes-agent -n venafi --set crds.venafiConnection.include=true --show-only templates/venafi-connection-rbac.yaml | grep -ivE '(helm|\/version)'

TODO(mael): Once we get the Makefile modules setup, we should generate this based on the Helm chart rather than having it hardcoded here. Ticket: https://venafi.atlassian.net/browse/VC-36331

Variables

This section is empty.

Functions

func FakeTPP

func FakeTPP(t testing.TB) (*httptest.Server, *x509.Certificate)

func FakeVenafiCloud

func FakeVenafiCloud(t *testing.T) (_ *httptest.Server, _ *x509.Certificate, setAssert func(AssertRequest))

func Parse

func Parse(yamlmanifest string) []ctrlruntime.Object

Parses the YAML manifest. Useful for inlining YAML manifests in Go test files, to be used in conjunction with `undent`.

func TrustCA added in v1.1.0

func TrustCA(t *testing.T, cl client.Client, cert *x509.Certificate)

Works with VenafiCloudClient and VenConnClient. Allows you to trust a given CA.

func Undent

func Undent(s string) string

Undent removes leading indentation/white-space from given string and returns it as a string. Useful for inlining YAML manifests in Go code. Inline YAML manifests in the Go test files makes it easier to read the test case as opposed to reading verbose-y Go structs.

This was copied from https://github.com/jimeh/Undent/blob/main/Undent.go, all credit goes to the author, Jim Myhrberg.

For code readability purposes, it is possible to start the literal string with "\n", in which case, the first line is ignored. For example, in the following example, name and labels have the same indentation level but aren't aligned due to the leading '`':

Undent(
`    name: foo
      labels:
        foo: bar`)

Instead, you can write a well-aligned text like this:

Undent(`
    name: foo
    labels:
       foo: bar`)

For code readability purposes, it is also possible to not have the correct number of indentations in the last line. For example:

Undent(`
    foo
    bar
`)

For code readability purposes, you can also omit the indentations for empty lines. For example:

Undent(`
    foo     <---- 4 spaces
            <---- no indentation here
    bar     <---- 4 spaces
`)

func VenConnStartWatching added in v1.1.0

func VenConnStartWatching(t *testing.T, cl client.Client)

Tests calling to VenConnClient.PostDataReadingsWithOptions must call this function to start the VenafiConnection watcher. If you don't call this, the test will stall.

func WithEnvtest

func WithEnvtest(t testing.TB) (_ *envtest.Environment, _ *rest.Config, kclient ctrlruntime.WithWatch)

To see the API server logs, set:

export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true

Types

type AssertRequest

type AssertRequest func(t testing.TB, r *http.Request)

Jump to

Keyboard shortcuts

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