radcli

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Contains support for automating the use of the rad CLI

Index

Constants

View Source
const (
	TestWorkspaceName   = "test-workspace"
	TestEnvironmentName = "test-environment"
)
View Source
const (
	HeartbeatInterval = 10 * time.Second
)

Variables

This section is empty.

Functions

func Create404Error

func Create404Error() error

Create404Error creates an error with a status code of 404.

func CreateResource

func CreateResource(resourceType string, resourceName string) generated.GenericResource

CreateResource creates a generic resource with the given resource type and name, and sets the ID, Name, Type and Location fields.

func CreateResourceGroup

func CreateResourceGroup(resourceGroupName string) v20231001preview.ResourceGroupResource

// CreateResourceGroup creates a ResourceGroupResource object with the given name and a generated ID.

func LoadConfig

func LoadConfig(t *testing.T, yamlData string) *viper.Viper

LoadConfig reads a YAML configuration from a string and returns a Viper object.

func LoadConfigWithWorkspace

func LoadConfigWithWorkspace(t *testing.T) *viper.Viper

LoadConfigWithWorkspace loads a config with a workspace and returns a viper instance.

func LoadEmptyConfig

func LoadEmptyConfig(t *testing.T) *viper.Viper

LoadEmptyConfig creates a viper instance with an empty workspaces configuration.

func SharedCommandValidation

func SharedCommandValidation(t *testing.T, factory func(framework framework.Factory) (*cobra.Command, framework.Runner))

SharedCommandValidation tests that the command created by the factory function has all the required fields set.

func SharedValidateValidation

func SharedValidateValidation(t *testing.T, factory func(framework framework.Factory) (*cobra.Command, framework.Runner), testcases []ValidateInput)

SharedValidateValidation runs a series of tests to validate command line arguments and flags, and returns an error if validation fails.

Types

type CLI

type CLI struct {
	T                *testing.T
	ConfigFilePath   string
	WorkingDirectory string
}

func NewCLI

func NewCLI(t *testing.T, configFilePath string) *CLI

NewCLI creates a new CLI instance with the given testing.T and config file path.

func (*CLI) ApplicationDelete

func (cli *CLI) ApplicationDelete(ctx context.Context, applicationName string) error

ApplicationDelete deletes the specified application deployed by Radius and returns an error if one occurs.

func (*CLI) ApplicationList

func (cli *CLI) ApplicationList(ctx context.Context) (string, error)

ApplicationList runs a command to list applications and returns the output as a string. It returns an error if the command fails.

func (*CLI) ApplicationShow

func (cli *CLI) ApplicationShow(ctx context.Context, applicationName string) (string, error)

ApplicationShow returns the output of running the "application show" command with the given application name as an argument, or an error if the command fails.

func (*CLI) BicepPublish

func (cli *CLI) BicepPublish(ctx context.Context, file, target string) (string, error)

BicepPublish runs the bicep publish command with the given file and target, and returns the output string or an error if the command fails.

func (*CLI) CliVersion

func (cli *CLI) CliVersion(ctx context.Context) (string, error)

CliVersion retrieves the version of the CLI by running the "version --cli" command.

func (*CLI) CreateCommand

func (cli *CLI) CreateCommand(ctx context.Context, args []string) (*exec.Cmd, func(<-chan struct{}), string)

CreateCommand creates an exec.Cmd that can be used to execute a `rad` CLI command. Most tests should use RunCommand, only use CreateCommand if the test you are writing needs more control over the execution of the command.

The second return value is the 'heartbeat' func. Tests using this function should start the heartbeat in a goroutine to produce logs while the command is running. The third return value is the command description which can be used in error messages.

func (*CLI) Deploy

func (cli *CLI) Deploy(ctx context.Context, templateFilePath string, environment string, application string, parameters ...string) error

Deploy runs the rad deploy command. It checks if the template file path exists and runs the command with the given parameters, returning an error if the command fails.

func (*CLI) EnvDelete

func (cli *CLI) EnvDelete(ctx context.Context, environmentName string) error

EnvDelete runs the command to delete an environment with the given name and returns an error if the command fails.

func (*CLI) EnvList

func (cli *CLI) EnvList(ctx context.Context) (string, error)

EnvList runs the "env list" command and returns the output as a string, or an error if the command fails.

func (*CLI) EnvShow

func (cli *CLI) EnvShow(ctx context.Context) (string, error)

EnvShow runs the "env show" command and returns the output as a string, or an error if the command fails.

func (*CLI) EnvStatus

func (cli *CLI) EnvStatus(ctx context.Context) (string, error)

EnvStatus runs the "env status" command and returns the output as a string. It returns an error if the command fails.

func (*CLI) RecipeList

func (cli *CLI) RecipeList(ctx context.Context, envName string) (string, error)

RecipeList runs the "recipe list" command with the given environment name and returns the output as a string, returning an error if the command fails.

func (*CLI) RecipeRegister

func (cli *CLI) RecipeRegister(ctx context.Context, envName, recipeName, templateKind, templatePath, resourceType string, plainHTTP bool) (string, error)

RecipeRegister runs a command to register a recipe with the given environment, template kind, template path and resource type, and returns the output string or an error.

func (*CLI) RecipeShow

func (cli *CLI) RecipeShow(ctx context.Context, envName, recipeName string, resourceType string) (string, error)

RecipeShow runs a command to show a recipe with the given environment name, recipe name and resource type, and returns the output string or an error.

func (*CLI) RecipeUnregister

func (cli *CLI) RecipeUnregister(ctx context.Context, envName, recipeName, resourceType string) (string, error)

RecipeUnregister runs a command to unregister a recipe from an environment, given the recipe name and resource type. It returns a string and an error if the command fails.

func (*CLI) ReportCommandResult

func (cli *CLI) ReportCommandResult(ctx context.Context, out string, description string, err error) error

ReportCommandResult can be used in tests to report the result of a command to the test infrastructure. Most test should use RunCommand. Only use ReportCommandResult if the test is using CreateCommand to control command execution.

func (*CLI) ResourceExpose

func (cli *CLI) ResourceExpose(ctx context.Context, applicationName string, resourceName string, localPort int, remotePort int) (string, error)

ResourceExpose runs a command to expose a resource from an application on a given port.

func (*CLI) ResourceList

func (cli *CLI) ResourceList(ctx context.Context, applicationName string) (string, error)

ResourceList runs the "resource list containers" command with the given application name and returns the output as a string, returning an error if the command fails.

func (*CLI) ResourceLogs

func (cli *CLI) ResourceLogs(ctx context.Context, applicationName string, resourceName string) (string, error)

ResourceLogs runs the CLI command to get the logs of a resource in an application.

func (*CLI) ResourceShow

func (cli *CLI) ResourceShow(ctx context.Context, resourceType string, resourceName string) (string, error)

ResourceShow runs the rad resource show command with the given resource type and name and returns the output string or an error if the command fails.

func (*CLI) Run

func (cli *CLI) Run(ctx context.Context, templateFilePath string, applicationName string, parameters ...string) (string, error)

Run runs the rad run command. This returns the command output on success or an error.

func (*CLI) RunCommand

func (cli *CLI) RunCommand(ctx context.Context, args []string) (string, error)

RunCommand executes a command and returns the output (stdout + stderr) as well as an error if the command fails. The output is *ALWAYS* returned even if the command fails.

func (*CLI) Version

func (cli *CLI) Version(ctx context.Context) (string, error)

Version runs the version command and returns the output as a string, or an error if the command fails.

type CLIError

type CLIError struct {
	v1.ErrorResponse
}

func (*CLIError) Error

func (err *CLIError) Error() string

CLIError.Error returns a string containing the error code and message of the error response.

func (*CLIError) GetFirstErrorCode

func (err *CLIError) GetFirstErrorCode() string

GetFirstErrorCode function goes down the error chain to find and return the code of the first error in the chain.

type ValidateInput

type ValidateInput struct {
	Name           string
	Input          []string
	ExpectedValid  bool
	ConfigHolder   framework.ConfigHolder
	ConfigureMocks func(mocks ValidateMocks)

	// ValidateCallback can be used to support a validation callback that will run after all other validation.
	//
	// This can be used to validate side-effects that occur in a Runner's Validate() function.
	ValidateCallback func(t *testing.T, runner framework.Runner)

	// CreateTempDirectory can be used to create a directory, and change directory into the
	// newly created directory before calling Validate. Set this field to the name of the directory
	// you want. The test framework will handle the cleanup.
	CreateTempDirectory string
}

type ValidateMocks

type ValidateMocks struct {
	Kubernetes                  *kubernetes.MockInterface
	Namespace                   *namespace.MockInterface
	Prompter                    *prompt.MockInterface
	Helm                        *helm.MockInterface
	ApplicationManagementClient *clients.MockApplicationsManagementClient
	AzureClient                 *azure.MockClient
	AWSClient                   *aws.MockClient
}

Jump to

Keyboard shortcuts

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