Documentation
¶
Overview ¶
Package testutil provides utilities and helpers for testing nctl.
Index ¶
- Constants
- Variables
- func CloudVirtualMachine(name, namespace, location string, ...) *infrastructure.CloudVirtualMachine
- func CountLines(s string) int
- func CreateTestKubeconfig(client *api.Client, organization string) (string, error)
- func GenerateED25519PrivateKey() (string, error)
- func GenerateRSAPrivateKey() (string, error)
- func Grafana(name, project string) *observability.Grafana
- func KeyValueStore(name, project string, location meta.LocationName) *storage.KeyValueStore
- func KongStreams(streams format.IOStreams) kong.Option
- func MustParseTime(format string, value string) time.Time
- func MySQL(name, project, location string) *storage.MySQL
- func MySQLDatabase(name, project, location string) *storage.MySQLDatabase
- func NewGitInformationService(t testing.TB) *gitInformationService
- func OpenSearch(name, project string, location meta.LocationName) *storage.OpenSearch
- func Postgres(name, project, location string) *storage.Postgres
- func PostgresDatabase(name, project, location string) *storage.PostgresDatabase
- func Projects(organization string, names ...string) []client.Object
- func RunNamedWithFlags(t *testing.T, cli any, vars kong.Vars, cmdPath []string, name string, ...) (*api.Client, string, error)
- func ServiceConnection(name, project string) *networking.ServiceConnection
- func SetupClient(t *testing.T, opts ...ClientSetupOption) *api.Client
- func StaticEgress(name, project, appName string) *networking.StaticEgress
- func StaticEgressForCluster(name, project, clusterName string) *networking.StaticEgress
- type ClientSetupOption
- func WithDefaultProject(project string) ClientSetupOption
- func WithInterceptorFuncs(f interceptor.Funcs) ClientSetupOption
- func WithKubeconfig() ClientSetupOption
- func WithNameIndexFor(obj runtime.Object) ClientSetupOption
- func WithObjects(objects ...client.Object) ClientSetupOption
- func WithOrganization(org string) ClientSetupOption
- func WithProjects(projects ...string) ClientSetupOption
- func WithProjectsFromResources(resources ...client.Object) ClientSetupOption
- type Credentials
- type GitInfoServiceParsed
- type GitInformationServiceResponse
- type SecretStore
- type VerifyRequestFunc
Constants ¶
const ( DefaultProject = "default" FakeJWTToken = "" /* 335-byte string literal not displayed */ ASAJWTToken = "" /* 412-byte string literal not displayed */ )
Variables ¶
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 CreateTestKubeconfig ¶
CreateTestKubeconfig creates a test kubeconfig which contains a nctl extension config with the given organization
func GenerateED25519PrivateKey ¶
GenerateED25519PrivateKey generates an ED25519 private key
func GenerateRSAPrivateKey ¶
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 ¶
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 MySQLDatabase ¶
func MySQLDatabase(name, project, location string) *storage.MySQLDatabase
func NewGitInformationService ¶
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 PostgresDatabase ¶
func PostgresDatabase(name, project, location string) *storage.PostgresDatabase
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 Credentials ¶ added in v1.22.0
type Credentials struct {
TokenStore, FileTokenStore SecretStore
ClientSecretStore, FileClientSecretStore SecretStore
}
Credentials are in-memory api.Credentials. The stores of api.StorageFile are separate from the others, so tests can tell which one a login used.
func (*Credentials) ClientSecrets ¶ added in v1.22.0
func (c *Credentials) ClientSecrets(storage api.Storage) api.SecretStore
func (*Credentials) Tokens ¶ added in v1.22.0
func (c *Credentials) Tokens(storage api.Storage) api.SecretStore
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 SecretStore ¶ added in v1.22.0
type SecretStore struct {
// contains filtered or unexported fields
}
SecretStore is an in-memory api.SecretStore.
func (*SecretStore) Delete ¶ added in v1.22.0
func (s *SecretStore) Delete(_ context.Context, key string) error
func (*SecretStore) Len ¶ added in v1.22.0
func (s *SecretStore) Len() int
Len returns the number of secrets in the store.
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