testutils

package
v0.0.0-...-fee1c07 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 7 Imported by: 0

README

testutils

A helper to write more concise and self-explanatory tests.

Examples

func TestICanInstallHelmChart(t *testing.T) {

	h, err := helm.Default()
	require.NoError(t, err)
	fd, err := os.CreateTemp("", "")
	require.NoError(t, err)
	defer fd.Close()
	stdout := os.Stdout
	os.Stdout = fd
	err = h.RepoAdd("examples", "https://helm.github.io/examples")
	require.NoError(t, err)
	os.Stdout = stdout

	client := fake.NewClientBuilder().Build()

	name := "not-found"

	helmtestutils.InstallFilteredHelmChart(t, context.Background(), client, "test-namespace", "release-name", "examples/hello-world", k8stestutils.ExtractObjectName(k8stestutils.WithKind("Deployment"), &name))

	assert.Equal(t, "release-name-hello-world", name)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallFilteredHelmChart

func InstallFilteredHelmChart(t require.TestingT, ctx context.Context, c client.Client, namespace, release, chart string, filters ...k8stestutils.Filter)
Example
package main

import (
	"context"
	"fmt"
	"os"

	helm "github.com/adevinta/go-helm-toolkit"
	helmtestutils "github.com/adevinta/go-helm-toolkit/testutils"

	k8stestutils "github.com/adevinta/go-k8s-toolkit/testutils"

	testutils "github.com/adevinta/go-testutils-toolkit"
	"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func main() {
	// use the real *testing.T from the test
	t := &testutils.FakeTest{Name: "TestICanInstallHelmChart"}

	h, err := helm.Default()
	if err != nil {
		return
	}
	fd, err := os.CreateTemp("", "")
	if err != nil {
		return
	}
	defer fd.Close()
	stdout := os.Stdout
	os.Stdout = fd
	h.RepoAdd("examples", "https://helm.github.io/examples")
	os.Stdout = stdout

	client := fake.NewClientBuilder().Build()

	name := "not-found"

	helmtestutils.InstallFilteredHelmChart(t, context.Background(), client, "test-namespace", "release-name", "examples/hello-world", k8stestutils.ExtractObjectName(k8stestutils.WithKind("Deployment"), &name))

	fmt.Println("name:", name)

	// Usually, this is done by the go framework
	fmt.Println(t)
}
Output:
name: release-name-hello-world
--- PASS: TestICanInstallHelmChart

Types

This section is empty.

Jump to

Keyboard shortcuts

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