testutil

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package testutil provides utilities and helpers for testing nctl.

Index

Constants

View Source
const (
	DefaultProject = "default"
	FakeJWTToken   = "" /* 335-byte string literal not displayed */
	ASAJWTToken    = "" /* 412-byte string literal not displayed */
)

Variables

View Source
var (
	// TODO: would be nice to get this from "github.com/ninech/apis/apps/v1alpha1"
	AppSizeNotSet apps.ApplicationSize = ""
	AppMicro      apps.ApplicationSize = "micro"
	AppMini       apps.ApplicationSize = "mini"
	AppStandard1  apps.ApplicationSize = "standard-1"
	AppStandard2  apps.ApplicationSize = "standard-2"
	AppStandard4  apps.ApplicationSize = "standard-4"

	StatusSuperseded apps.ReleaseProcessStatus = "superseded"
	StatusAvailable  apps.ReleaseProcessStatus = "available"
)

Functions

func CloudVirtualMachine

func CloudVirtualMachine(name, namespace, location string, powerstate infrastructure.VirtualMachinePowerState) *infrastructure.CloudVirtualMachine

func CountLines

func CountLines(s string) int

func CreateTestKubeconfig

func CreateTestKubeconfig(client *api.Client, organization string) (string, error)

CreateTestKubeconfig creates a test kubeconfig which contains a nctl extension config with the given organization

func GenerateED25519PrivateKey

func GenerateED25519PrivateKey() (string, error)

GenerateED25519PrivateKey generates an ED25519 private key

func GenerateRSAPrivateKey

func GenerateRSAPrivateKey() (string, error)

GenerateRSAPrivateKey generates an RSA private key

func Grafana

func Grafana(name, project string) *observability.Grafana

func KeyValueStore

func KeyValueStore(name, project string, location meta.LocationName) *storage.KeyValueStore

func KongStreams

func KongStreams(streams format.IOStreams) kong.Option

KongStreams returns a Kong option binding streams for the hooks of the commands and making them the writers of Kong, as the parser of nctl does.

func MustParseTime

func MustParseTime(format string, value string) time.Time

func MySQL

func MySQL(name, project, location string) *storage.MySQL

func MySQLDatabase

func MySQLDatabase(name, project, location string) *storage.MySQLDatabase

func NewGitInformationService

func NewGitInformationService(t testing.TB) *gitInformationService

NewGitInformationService returns a new git information service mock. It can be used to verify requests sent to it and also to just return with a previously set response. It logs the errors of serving a request to the output of t.

func OpenSearch

func OpenSearch(name, project string, location meta.LocationName) *storage.OpenSearch

func Postgres

func Postgres(name, project, location string) *storage.Postgres

func PostgresDatabase

func PostgresDatabase(name, project, location string) *storage.PostgresDatabase

func Projects

func Projects(organization string, names ...string) []client.Object

Projects returns projects with the given organization namespace set

func RunNamedWithFlags

func RunNamedWithFlags(
	t *testing.T,
	cli any,
	vars kong.Vars,
	cmdPath []string,
	name string,
	flags []string,
	afterParse func() (namePtr *string, waitPtr *bool, waitTimeoutPtr *time.Duration),
	clientOpts ...ClientSetupOption,
) (*api.Client, string, error)

RunNamedWithFlags is a generic test helper for running Kong command. Parameters:

  • cli: pointer to the CLI root (e.g. &struct{ Bucket *bucketCmd `cmd:"" name:"bucket"` }{})
  • cmdPath: command path (e.g. []string{"bucket"} or {"bucket","update"})
  • name: optional positional NAME; if empty, defaults to "test-"+t.Name()
  • flags: command-line flags only (the helper prepends cmdPath + NAME)
  • afterParse: closure returning pointers to defaulted fields (e.g. Name, WaitTimeout)
  • clientOpts: passthrough options for SetupClient (e.g. WithObjects(...))

Safe to use with t.Parallel(): each test gets a unique name. Inspired by https://github.com/alecthomas/kong/blob/v1.12.1/kong_test.go#L454

func ServiceConnection

func ServiceConnection(name, project string) *networking.ServiceConnection

func SetupClient

func SetupClient(t *testing.T, opts ...ClientSetupOption) *api.Client

func StaticEgress

func StaticEgress(name, project, appName string) *networking.StaticEgress

func StaticEgressForCluster

func StaticEgressForCluster(name, project, clusterName string) *networking.StaticEgress

Types

type ClientSetupOption

type ClientSetupOption func(*clientSetup)

func WithDefaultProject

func WithDefaultProject(project string) ClientSetupOption

WithDefaultProject sets the default project of the client

func WithInterceptorFuncs

func WithInterceptorFuncs(f interceptor.Funcs) ClientSetupOption

func WithKubeconfig

func WithKubeconfig() ClientSetupOption

WithKubeconfig creates a fake kubeconfig which gets removed once the passed test finished

func WithNameIndexFor

func WithNameIndexFor(obj runtime.Object) ClientSetupOption

WithNameIndexFor adds a name index to the fake client set for the passed object type

func WithObjects

func WithObjects(objects ...client.Object) ClientSetupOption

WithObjects sets the objects which can be returned from the client

func WithOrganization

func WithOrganization(org string) ClientSetupOption

WithOrganization sets the organization of the client

func WithProjects

func WithProjects(projects ...string) ClientSetupOption

WithProjects exclusively sets the projects which should be created

func WithProjectsFromResources

func WithProjectsFromResources(resources ...client.Object) ClientSetupOption

WithProjectsFromResources reads the namespaces of all given resources and adds them (unique) to the clientSetups project list. Use this on your own risk in combination with `WithProjects`. Make make sure that `WithProjects` is set before this function call in a functional options list. Otherwise you will overwrite the results from this function.

type GitInfoServiceParsed

type GitInfoServiceParsed struct {
	Token   string
	Method  string
	Request apps.GitExploreRequest
}

GitInfoServiceParsed represents are parsed request received by the git information service

type GitInformationServiceResponse

type GitInformationServiceResponse struct {
	// Code is the status code to be set
	Code int
	// Content describes the GitExploreResponse to be returned.
	Content apps.GitExploreResponse
	// Raw allows to return any text instead of a real GitExploreResponse.
	// If it is set, it has precedence over the Content field.
	Raw *string
}

GitInformationServiceResponse describes a response of the git information service

type VerifyRequestFunc

type VerifyRequestFunc func(p GitInfoServiceParsed, err error)

VerifyRequestFunc can be used to verify the parsed request which was sent to the git information service

Jump to

Keyboard shortcuts

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