Documentation
¶
Overview ¶
Package framework defines the integration and end-to-end test case for cli core
Package framework defines the integration and end-to-end test case for cli core ¶
Package framework defines the integration and end-to-end test case for cli core
Index ¶
- Constants
- Variables
- func CLICoreDescribe(text string, body func()) bool
- func ContainsAnyString(stdOut *bytes.Buffer, contains []string) error
- func ContainsString(stdOut *bytes.Buffer, contains string) error
- func CreateDir(dir string) error
- func GetHomeDir() string
- func NotContainsString(stdOut *bytes.Buffer, contains string) error
- func RandomNumber(length int) string
- func RandomString(length int) string
- func SliceToSet(slice []string) map[string]struct{}
- type CLIPlugin
- type CliOps
- type ClusterInfo
- type ClusterOps
- type CmdOps
- type ConfigLifecycleOps
- type ContainerRuntime
- type ContextCmdOps
- type ContextCreateOps
- type ContextInfo
- type ContextListInfo
- type DiscoveryOptions
- type Docker
- type Framework
- type GeneratePluginOps
- type ImgpkgOps
- type KindCluster
- type PluginBasicOps
- type PluginCmdOps
- type PluginCompatibilityConf
- type PluginHelperOps
- type PluginListInfo
- type PluginMeta
- func (p *PluginMeta) GetName() string
- func (p *PluginMeta) GetRegistryDiscoveryURL() string
- func (p *PluginMeta) SetAliases(alias []string) *PluginMeta
- func (p *PluginMeta) SetArch(arch string) *PluginMeta
- func (p *PluginMeta) SetDescription(description string) *PluginMeta
- func (p *PluginMeta) SetDiscoveryType(discoveryType string) *PluginMeta
- func (p *PluginMeta) SetGroup(group string) *PluginMeta
- func (p *PluginMeta) SetHidden(hidden bool) *PluginMeta
- func (p *PluginMeta) SetName(name string) *PluginMeta
- func (p *PluginMeta) SetOS(osType string) *PluginMeta
- func (p *PluginMeta) SetOptional(optional bool) *PluginMeta
- func (p *PluginMeta) SetSHA(sha string) *PluginMeta
- func (p *PluginMeta) SetTarget(target string) *PluginMeta
- func (p *PluginMeta) SetVersion(version string) *PluginMeta
- type PluginRegistry
- type PluginSourceOps
- type PublishPluginOps
Constants ¶
const ( ConfigFileName = "config.yaml" ConfigNGFileName = "config-ng.yaml" ConfigFileDir = ".config/tanzu/" )
const ( CliCore = "[CLI-Core]" TanzuInit = "tanzu init" TanzuVersion = "tanzu version" // Config commands ConfigSet = "tanzu config set " ConfigGet = "tanzu config get " ConfigUnset = "tanzu config unset " ConfigInit = "tanzu config init" ConfigServerList = "tanzu config server list" ConfigServerDelete = "tanzu config server delete " // Plugin commands AddPluginSource = "tanzu plugin source add --name %s --type %s --uri %s" DeletePluginSource = "tanzu plugin source delete %s" ListPluginsCmdInJSON = "tanzu plugin list -o json" SearchPluginsCmd = "tanzu plugin search" InstallPLuginCmd = "tanzu plugin install %s" UninstallPLuginCmd = "tanzu plugin delete %s --yes" JSONOutput = " -o json" TestPluginsPrefix = "test-plugin-" PluginSubCommand = "tanzu %s" // Central repository TanzuCliE2ETestCentralRepositoryURL = "TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL" // General constants True = "true" Installed = "installed" // Context commands CreateContextWithEndPoint = "tanzu context create --endpoint %s --name %s" CreateContextWithEndPointStaging = "tanzu context create --endpoint %s --name %s --staging" CreateContextWithKubeconfigFile = "tanzu context create --kubeconfig %s --kubecontext %s --name %s" CreateContextWithDefaultKubeconfigFile = "tanzu context create --kubecontext %s --name %s" UseContext = "tanzu context use %s" GetContext = "tanzu context get %s" ListContextOutputInJSON = "tanzu context list -o json" DeleteContext = "tanzu context delete %s --yes" TanzuAPIToken = "TANZU_API_TOKEN" //nolint:gosec TanzuCliTmcUnstableURL = "TANZU_CLI_TMC_UNSTABLE_URL" KindClusterCreate = "kind create cluster --name %s" KindClusterStatus = "kubectl cluster-info --context %s" KindClusterDelete = "kind delete cluster --name %s" KindClusterGet = "kind get clusters " KindClusterInfo = "kubectl cluster-info --context %s" KindCreateCluster = "kind create cluster --name " DockerInfo = "docker info" StartDockerUbuntu = "sudo systemctl start docker" StopDockerUbuntu = "sudo systemctl stop docker" TestDir = ".tanzu-cli-e2e" TestPluginsDir = ".e2e-test-plugins" TargetTypeTMC = "mission-control" TargetTypeK8s = "kubernetes" )
const ( DefaultCLIPluginBucket = "/tkg/tanzu_core/tanzu-cli-plugins/" DefaultRegistryName = "registry" DefaultRegistryPort = "5001" )
const FailedToCreateContext = "failed to create context"
const FailedToCreateContextWithStdout = FailedToCreateContext + ", stdout:%s"
const FailedToDeleteContext = "failed to delete context"
const GeneratedValuesTemplate = `#@data/values
#@overlay/match-child-defaults missing_ok=True
---`
const ImagesTemplate = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
kind: ImagesLock`
const ScriptBasedPluginTemplate = `` /* 491-byte string literal not displayed */
Variables ¶
var TestDirPath string
var TestPluginsDirPath string
var TestStandalonePluginsPath string
Functions ¶
func CLICoreDescribe ¶
CLICoreDescribe annotates the test with the CLICore label.
func ContainsAnyString ¶
ContainsAnyString checks that the given buffer contains any of the given set of strings.
func ContainsString ¶
ContainsString checks that the given buffer contains the string.
func GetHomeDir ¶ added in v0.0.4
func GetHomeDir() string
func NotContainsString ¶
NotContainsString checks that the given buffer not contains the string if contains then throws error.
func RandomNumber ¶ added in v0.0.4
RandomNumber generates random string of given length
func RandomString ¶
RandomString generates random string of given length
func SliceToSet ¶ added in v0.0.4
SliceToSet converts the given slice to set type
Types ¶
type CLIPlugin ¶
type CLIPlugin struct {
metav1.TypeMeta `yaml:",inline"`
Metadata metav1.ObjectMeta `json:"metadata"`
Spec cliv1alpha1.CLIPluginSpec `json:"spec"`
}
CLIPlugin for plugin overlay info
type CliOps ¶
type CliOps interface {
CliInit() error
CliVersion() (string, error)
InstallCLI(version string) error
UninstallCLI(version string) error
}
CliOps performs basic cli operations
type ClusterInfo ¶ added in v0.0.4
type ClusterInfo struct {
Name string
ClusterContext string
EndPoint string
KubeConfigPath string
APIKey string
}
ClusterInfo holds the general cluster details
type ClusterOps ¶
type ClusterOps interface {
// CreateCluster creates the cluster with given name
CreateCluster(clusterName string) (output string, err error)
// DeleteCluster deletes the cluster with given name
DeleteCluster(clusterName string) (output string, err error)
// ClusterStatus checks the status of the cluster for given cluster name
ClusterStatus(clusterName string) (output string, err error)
// GetClusterEndpoint returns the cluster endpoint for the given cluster name
GetClusterEndpoint(clusterName string) (endpoint string, err error)
// GetClusterContext returns the given cluster kubeconfig context
GetClusterContext(clusterName string) string
// GetKubeconfigPath returns the default kubeconfig path
GetKubeconfigPath() string
}
ClusterOps has helper operations to perform on cluster
type CmdOps ¶
type CmdOps interface {
Exec(command string) (stdOut, stdErr *bytes.Buffer, err error)
ExecContainsString(command, contains string) error
ExecContainsAnyString(command string, contains []string) error
ExecContainsErrorString(command, contains string) error
ExecNotContainsStdErrorString(command, contains string) error
ExecNotContainsString(command, contains string) error
}
CmdOps performs the Command line exec operations
type ConfigLifecycleOps ¶
type ConfigLifecycleOps interface {
// ConfigSetFeatureFlag sets the tanzu config feature flag
ConfigSetFeatureFlag(path, value string) error
// ConfigGetFeatureFlag gets the tanzu config feature flag
ConfigGetFeatureFlag(path string) (string, error)
// ConfigUnsetFeature un-sets the tanzu config feature flag
ConfigUnsetFeature(path string) error
// ConfigInit performs "tanzu config init"
ConfigInit() error
// GetConfig gets the tanzu config
GetConfig() (*configapi.ClientConfig, error)
// ConfigServerList returns the server list
ConfigServerList() error
// ConfigServerDelete deletes given server from tanzu config
ConfigServerDelete(serverName string) error
// DeleteCLIConfigurationFiles deletes cli configuration files
DeleteCLIConfigurationFiles() error
// IsCLIConfigurationFilesExists checks the existence of cli configuration files
IsCLIConfigurationFilesExists() bool
}
ConfigLifecycleOps performs "tanzu config" command operations
func NewConfOps ¶
func NewConfOps() ConfigLifecycleOps
type ContainerRuntime ¶
type ContainerRuntime interface {
StartContainerRuntime() (output string, err error)
ContainerRuntimeStatus() (status string, err error)
StopContainerRuntime() (output string, err error)
}
ContainerRuntime has operations to perform on container runtime
type ContextCmdOps ¶ added in v0.0.4
type ContextCmdOps interface {
// ContextCreateOps helps context create operations
ContextCreateOps
// UseContext helps to run 'context use' command
UseContext(contextName string) error
// GetContext helps to run `context get` command
GetContext(contextName string) (ContextInfo, error)
// ListContext helps to run `context list` command
ListContext() ([]ContextListInfo, error)
// DeleteContext helps to run `context delete` command
DeleteContext(contextName string) error
// GetActiveContext returns current active context
GetActiveContext(targetType string) (string, error)
}
ContextCmdOps helps to run Context lifecycle operations
func NewContextCmdOps ¶ added in v0.0.4
func NewContextCmdOps() ContextCmdOps
type ContextCreateOps ¶ added in v0.0.4
type ContextCreateOps interface {
// CreateConextWithEndPoint creates a context with a given endpoint URL
CreateConextWithEndPoint(contextName, endpoint string) error
// CreateConextWithEndPointStaging creates a context with a given endpoint URL for staging
CreateConextWithEndPointStaging(contextName, endpoint string) error
// CreateConextWithKubeconfig creates a context with the given kubeconfig file path and a context from the kubeconfig file
CreateConextWithKubeconfig(contextName, kubeconfigPath, kubeContext string) error
// CreateContextWithDefaultKubeconfig creates a context with the default kubeconfig file and a given input context name if it exists in the default kubeconfig file
CreateContextWithDefaultKubeconfig(contextName, kubeContext string) error
}
ContextCreateOps helps to run context create command
func NewContextCreateOps ¶ added in v0.0.4
func NewContextCreateOps() ContextCreateOps
type ContextInfo ¶ added in v0.0.4
type ContextListInfo ¶ added in v0.0.4
type DiscoveryOptions ¶
type Docker ¶
type Docker interface {
ContainerRuntime
}
Docker is the container runtime of type docker
type Framework ¶
type Framework struct {
CliOps
Config ConfigLifecycleOps
KindCluster ClusterOps
PluginCmd PluginCmdOps // performs plugin command operations
PluginHelper PluginHelperOps // helper (pre-setup) for plugin cmd operations
ContextCmd ContextCmdOps
}
Framework has all helper functions to write CLI e2e test cases
func NewFramework ¶
func NewFramework() *Framework
type GeneratePluginOps ¶
type GeneratePluginOps interface {
// GeneratePluginBinaries generates plugin binaries for given plugin metadata and return generated plugin binary file paths
GeneratePluginBinaries(pluginsMeta []*PluginMeta) ([]string, []error)
}
GeneratePluginOps helps to generate script-based plugin binaries, and plugin binaries can be used to perform plugin testing like, add plugin source, list, and install plugins. And call sub-commands such as info and version.
func NewScriptBasedPlugins ¶
func NewScriptBasedPlugins() GeneratePluginOps
type ImgpkgOps ¶
type ImgpkgOps interface {
PushBinary(filepath, registryBucketURL string) (registryURL string, err error)
PushBundle(filepath, registryBucketURL string) (registryURL string, err error)
PullBinary(url string, outputPath string) (stdOut string, err error)
PullBundle(url string, outputPath string) (stdOut string, err error)
}
func NewImgpkgOps ¶
func NewImgpkgOps() ImgpkgOps
type KindCluster ¶
type KindCluster interface {
ClusterOps
}
KindCluster performs k8s KIND cluster operations
func NewKindCluster ¶
func NewKindCluster(docker Docker) KindCluster
type PluginBasicOps ¶
type PluginBasicOps interface {
// ListPlugins lists all plugins by running 'tanzu plugin list' command
ListPlugins() ([]PluginListInfo, error)
// SearchPlugins searches all plugins for given filter (keyword|regex) by running 'tanzu plugin search' command
SearchPlugins(filter string) ([]PluginListInfo, error)
// InstallPlugin installs given plugin
InstallPlugin(pluginName string) error
// UninstallPlugin uninstalls given plugin
UninstallPlugin(pluginName string) error
// ExecuteSubCommand executes specific plugin sub-command
ExecuteSubCommand(pluginWithSubCommand string) (string, error)
}
PluginBasicOps helps to perform the plugin command operations
type PluginCmdOps ¶
type PluginCmdOps interface {
PluginBasicOps
PluginSourceOps
}
PluginCmdOps helps to perform the plugin and its sub-commands lifecycle operations
func NewPluginLifecycleOps ¶
func NewPluginLifecycleOps() PluginCmdOps
type PluginCompatibilityConf ¶ added in v0.79.0
type PluginHelperOps ¶
type PluginHelperOps interface {
GeneratePluginOps
PublishPluginOps
}
PluginHelperOps helps to generate and publish plugins
func NewPluginOps ¶
func NewPluginOps(generatePluginOps GeneratePluginOps, publishPluginOps PublishPluginOps) PluginHelperOps
type PluginListInfo ¶
type PluginMeta ¶
type PluginMeta struct {
// contains filtered or unexported fields
}
func NewPluginMeta ¶
func NewPluginMeta() *PluginMeta
func (*PluginMeta) GetName ¶
func (p *PluginMeta) GetName() string
func (*PluginMeta) GetRegistryDiscoveryURL ¶
func (p *PluginMeta) GetRegistryDiscoveryURL() string
func (*PluginMeta) SetAliases ¶
func (p *PluginMeta) SetAliases(alias []string) *PluginMeta
func (*PluginMeta) SetArch ¶
func (p *PluginMeta) SetArch(arch string) *PluginMeta
func (*PluginMeta) SetDescription ¶
func (p *PluginMeta) SetDescription(description string) *PluginMeta
func (*PluginMeta) SetDiscoveryType ¶
func (p *PluginMeta) SetDiscoveryType(discoveryType string) *PluginMeta
func (*PluginMeta) SetGroup ¶
func (p *PluginMeta) SetGroup(group string) *PluginMeta
func (*PluginMeta) SetHidden ¶
func (p *PluginMeta) SetHidden(hidden bool) *PluginMeta
func (*PluginMeta) SetName ¶
func (p *PluginMeta) SetName(name string) *PluginMeta
func (*PluginMeta) SetOS ¶
func (p *PluginMeta) SetOS(osType string) *PluginMeta
func (*PluginMeta) SetOptional ¶
func (p *PluginMeta) SetOptional(optional bool) *PluginMeta
func (*PluginMeta) SetSHA ¶
func (p *PluginMeta) SetSHA(sha string) *PluginMeta
func (*PluginMeta) SetTarget ¶
func (p *PluginMeta) SetTarget(target string) *PluginMeta
func (*PluginMeta) SetVersion ¶
func (p *PluginMeta) SetVersion(version string) *PluginMeta
type PluginRegistry ¶
type PluginRegistry interface {
// StartRegistry starts plugin registry
StartRegistry() (url string, err error)
// StopRegistry stops plugin registry
StopRegistry() error
// IsRegistryRunning validates plugin registry status
IsRegistryRunning() (bool, error)
// GetRegistryURLWithDefaultCLIPluginsBucket returns the default registry url with default bucket for CLI plugin's
GetRegistryURLWithDefaultCLIPluginsBucket() (url string)
}
func NewLocalOCIRegistry ¶
func NewLocalOCIRegistry(registryName, port string) PluginRegistry
type PluginSourceOps ¶
type PluginSourceOps interface {
// AddPluginDiscoverySource adds plugin discovery source, and returns stdOut and error info
AddPluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error)
// DeletePluginDiscoverySource removes the plugin discovery source, and returns stdOut and error info
DeletePluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error)
}
PluginSourceOps helps 'plugin source' commands
type PublishPluginOps ¶
type PublishPluginOps interface {
// PublishPluginBinary publishes the plugin binaries to given registry bucket and returns the plugin distribution urls
PublishPluginBinary(pluginsInfo []*PluginMeta) (distributionUrls []string, errs []error)
// GeneratePluginBundle generates plugin bundle in local file system for given plugin metadata
GeneratePluginBundle(pluginsMeta []*PluginMeta) ([]string, []error)
// PublishPluginBundle publishes the plugin bundles to given registry bucket and returns the plugins discovery urls
PublishPluginBundle(pluginsInfo []*PluginMeta) (discoveryUrls []string, errs []error)
}
PublishPluginOps helps to publish plugin binaries and plugin bundles
func NewLocalOCIPluginOps ¶
func NewLocalOCIPluginOps(registry PluginRegistry) PublishPluginOps
Source Files
¶
- cli_lifecycle_operations.go
- cluster_container_runtime.go
- cluster_interface.go
- cluster_kind.go
- cmd_exec_operations.go
- config_lifecycle_operations.go
- context_create_operations.go
- context_lifecycle_operations.go
- framework.go
- framework_helper.go
- imgpkg_operations.go
- output_handling.go
- plugin_lifecycle_operations.go
- plugin_meta.go
- plugin_operations.go
- plugin_registry.go
- templates.go