framework

package
v0.80.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

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

View Source
const (
	ConfigFileName   = "config.yaml"
	ConfigNGFileName = "config-ng.yaml"
	ConfigFileDir    = ".config/tanzu/"
)
View Source
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 %s -y"

	// Plugin commands
	AddPluginSource                     = "tanzu plugin source add --name %s --type %s --uri %s"
	UpdatePluginSource                  = "tanzu plugin source update %s --type %s --uri %s"
	ListPluginSourcesWithJSONOutputFlag = "tanzu plugin source list -o json"
	DeletePluginSource                  = "tanzu plugin source delete %s"
	ListPluginsCmdWithJSONOutputFlag    = "tanzu plugin list -o json"
	SearchPluginsCmd                    = "tanzu plugin search"
	SearchPluginGroupsCmd               = "tanzu plugin group search"
	InstallPluginCmd                    = "tanzu plugin install %s"
	InstallPluginFromGroupCmd           = "tanzu plugin install %s --group %s"
	InstallAllPluginsFromGroupCmd       = "tanzu plugin install --group %s"
	DescribePluginCmd                   = "tanzu plugin describe %s"
	UninstallPLuginCmd                  = "tanzu plugin delete %s --yes"
	CleanPluginsCmd                     = "tanzu plugin clean"
	JSONOutput                          = " -o json"
	TestPluginsPrefix                   = "test-plugin-"
	PluginSubCommand                    = "tanzu %s"
	PluginKey                           = "%s_%s_%s" // Plugins - Name_Target_Versions

	// Central repository
	CentralRepositoryPreReleaseRepoImage     = "TANZU_CLI_PRE_RELEASE_REPO_IMAGE"
	TanzuCliE2ETestCentralRepositoryURL      = "TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL"
	TanzuCliE2ETestLocalCentralRepositoryURL = "TANZU_CLI_E2E_TEST_LOCAL_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"

	TMC            = "tmc"
	TKG            = "tkg"
	TestDir        = ".tanzu-cli-e2e"
	TestPluginsDir = ".e2e-test-plugins"
	SourceType     = "oci"
	GlobalTarget   = "global"

	// log info
	ExecutingCommand = "Executing command: %s"

	// Error messages
	UnableToFindPluginForTarget                   = "unable to find plugin '%s' for target '%s'"
	UnableToFindPlugin                            = "unable to find plugin '%s'"
	InvalidTargetSpecified                        = "" /* 130-byte string literal not displayed */
	InvalidTargetGlobal                           = "invalid target for plugin: global"
	UnknownDiscoverySourceType                    = "unknown discovery source type"
	DiscoverySourceNotFound                       = "cli discovery source not found"
	ErrorLogForCommandWithErrAndStdErr            = "error while executing command:'%s', error:'%s' stdErr:'%s'"
	FailedToConstructJSONNodeFromOutputAndErrInfo = "failed to construct json node from output:'%s' error:'%s' "
	FailedToConstructJSONNodeFromOutput           = "failed to construct json node from output:'%s'"

	// config related constants
	FailedToCreateContext           = "failed to create context"
	FailedToCreateContextWithStdout = FailedToCreateContext + ", stdout:%s"
	ContextCreated                  = "context %s created successfully"
	ContextDeleted                  = "context %s deleted successfully"
	ConfigServerDeleted             = "config server %s deleted successfully"
	FailedToDeleteContext           = "failed to delete context"
)
View Source
const (
	DefaultCLIPluginBucket = "/tkg/tanzu_core/tanzu-cli-plugins/"
	DefaultRegistryName    = "registry"
	DefaultRegistryPort    = "5001"
)
View Source
const GeneratedValuesTemplate = `#@data/values
#@overlay/match-child-defaults missing_ok=True

---`
View Source
const ImagesTemplate = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
kind: ImagesLock`
View Source
const ScriptBasedPluginTemplate = `` /* 491-byte string literal not displayed */

Variables

View Source
var (
	TestDirPath               string
	TestPluginsDirPath        string
	TestStandalonePluginsPath string
)
View Source
var PluginGroupsForLifeCycleTests []*PluginGroup

PluginGroupsForLifeCycleTests is list of plugin groups (which are published in local central repo) used in plugin group life cycle test cases

View Source
var PluginsForLifeCycleTests []*PluginInfo

PluginsForLifeCycleTests is list of plugins (which are published in local central repo) used in plugin life cycle test cases

Functions

func CLICoreDescribe

func CLICoreDescribe(text string, body func()) bool

CLICoreDescribe annotates the test with the CLICore label.

func ContainsAnyString

func ContainsAnyString(stdOut *bytes.Buffer, contains []string) error

ContainsAnyString checks that the given buffer contains any of the given set of strings.

func ContainsString

func ContainsString(stdOut *bytes.Buffer, contains string) error

ContainsString checks that the given buffer contains the string.

func CreateDir

func CreateDir(dir string) error

CreateDir creates directory if not exists

func ExecuteCmdAndBuildJSONOutput added in v0.0.11

func ExecuteCmdAndBuildJSONOutput[T PluginInfo | PluginSearch | PluginGroup | PluginSourceInfo | configapi.ClientConfig | Server | ContextListInfo](cmdExe CmdOps, cmd string) ([]*T, error)

ExecuteCmdAndBuildJSONOutput is generic function to execute given command and build JSON output and return

func GetHomeDir added in v0.0.4

func GetHomeDir() string

func GetMapKeys added in v0.0.11

func GetMapKeys[K string, V *PluginInfo](m map[K][]V) []*K

GetMapKeys takes map[K]any and returns the slice of all map keys

func NotContainsString

func NotContainsString(stdOut *bytes.Buffer, contains string) error

NotContainsString checks that the given buffer not contains the string if contains then throws error.

func PluginGroupToMap added in v0.0.11

func PluginGroupToMap(pluginGroups []*PluginGroup) map[string]*PluginGroup

PluginGroupToMap converts the given slice of PluginGroups to map (PluginGroup name is the key) and PluginGroup is the value

func PluginListToMap added in v0.0.4

func PluginListToMap(pluginsList []*PluginInfo) map[string]*PluginInfo

PluginListToMap converts the given PluginInfo slice to map type, key is combination of plugin's name_target_version and value is PluginInfo

func PluginListToSet added in v0.0.4

func PluginListToSet(pluginsToInstall []*PluginInfo) map[string]struct{}

PluginListToSet converts the given PluginInfo slice to set type, key is combination of plugin's name_target_version

func RandomNumber added in v0.0.4

func RandomNumber(length int) string

RandomNumber generates random string of given length

func RandomString

func RandomString(length int) string

RandomString generates random string of given length

func SliceToSet added in v0.0.4

func SliceToSet(slice []string) map[string]struct{}

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

func NewCliOps

func NewCliOps() CliOps

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

func NewCmdOps

func NewCmdOps() CmdOps

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() ([]*Server, 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 {
	// CreateContextWithEndPoint creates a context with a given endpoint URL
	CreateContextWithEndPoint(contextName, endpoint string) error
	// CreateContextWithEndPointStaging creates a context with a given endpoint URL for staging
	CreateContextWithEndPointStaging(contextName, endpoint string) error
	// CreateContextWithKubeconfig creates a context with the given kubeconfig file path and a context from the kubeconfig file
	CreateContextWithKubeconfig(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 ContextInfo struct {
	Name        string `json:"name"`
	Target      string `json:"target"`
	ClusterOpts struct {
		Path                string `json:"path"`
		Context             string `json:"context"`
		IsManagementCluster bool   `json:"isManagementCluster"`
	} `json:"clusterOpts"`
}

type ContextListInfo added in v0.0.4

type ContextListInfo struct {
	Endpoint            string `json:"endpoint"`
	Iscurrent           string `json:"iscurrent"`
	Ismanagementcluster string `json:"ismanagementcluster"`
	Kubeconfigpath      string `json:"kubeconfigpath"`
	Kubecontext         string `json:"kubecontext"`
	Name                string `json:"name"`
	Type                string `json:"type"`
}

type DiscoveryOptions

type DiscoveryOptions struct {
	Name       string
	SourceType string
	URI        string
}

type Docker

type Docker interface {
	ContainerRuntime
}

Docker is the container runtime of type docker

func NewDocker

func NewDocker() 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() ([]*PluginInfo, error)
	// SearchPlugins searches all plugins for given filter (keyword|regex) by running 'tanzu plugin search' command
	SearchPlugins(filter string) ([]*PluginInfo, error)
	// InstallPlugin installs given plugin and flags
	InstallPlugin(pluginName, target, versions string) error
	// DescribePlugin describes given plugin and flags
	DescribePlugin(pluginName, target string) (string, error)
	// UninstallPlugin uninstalls/deletes given plugin
	UninstallPlugin(pluginName, target string) error
	// DeletePlugin deletes/uninstalls given plugin
	DeletePlugin(pluginName, target string) error
	// ExecuteSubCommand executes specific plugin sub-command
	ExecuteSubCommand(pluginWithSubCommand string) (string, error)
	// CleanPlugins executes the plugin clean command to delete all existing plugins
	CleanPlugins() error
}

PluginBasicOps helps to perform the plugin command operations

type PluginCmdOps

type PluginCmdOps interface {
	PluginBasicOps
	PluginSourceOps
	PluginGroupOps
}

PluginCmdOps helps to perform the plugin and its sub-commands lifecycle operations

func NewPluginLifecycleOps

func NewPluginLifecycleOps() PluginCmdOps

type PluginGroup added in v0.0.11

type PluginGroup struct {
	Group string `json:"group"`
}

type PluginGroupOps added in v0.0.11

type PluginGroupOps interface {
	// SearchPluginGroups performs plugin group search
	// input: flagsWithValues - flags and values if any
	SearchPluginGroups(flagsWithValues string) ([]*PluginGroup, error)

	// InstallPluginsFromGroup a plugin or all plugins from the given plugin group
	InstallPluginsFromGroup(pluginNameORAll, groupName string) error
}

type PluginHelperOps

type PluginHelperOps interface {
	GeneratePluginOps
	PublishPluginOps
}

PluginHelperOps helps to generate and publish plugins

func NewPluginOps

func NewPluginOps(generatePluginOps GeneratePluginOps, publishPluginOps PublishPluginOps) PluginHelperOps

type PluginInfo added in v0.0.4

type PluginInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Target      string `json:"target"`
	Discovery   string `json:"discovery"`
	Scope       string `json:"scope"`
	Status      string `json:"status"`
	Version     string `json:"version"`
}

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 PluginSearch added in v0.0.11

type PluginSearch struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Target      string `json:"target"`
	Latest      string `json:"latest"`
}

type PluginSourceInfo added in v0.0.4

type PluginSourceInfo struct {
	Name  string `json:"name"`
	Scope string `json:"scope"`
	Type  string `json:"type"`
}

type PluginSourceOps

type PluginSourceOps interface {
	// AddPluginDiscoverySource adds plugin discovery source, and returns stdOut and error info
	AddPluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error)

	// UpdatePluginDiscoverySource updates plugin discovery source, and returns stdOut and error info
	UpdatePluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error)

	// DeletePluginDiscoverySource removes the plugin discovery source, and returns stdOut and error info
	DeletePluginDiscoverySource(pluginSourceName string) (string, error)

	// ListPluginSources returns all available plugin discovery sources
	ListPluginSources() ([]*PluginSourceInfo, 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

type Server added in v0.0.4

type Server struct {
	Context  string `json:"context"`
	Endpoint string `json:"endpoint"`
	Name     string `json:"name"`
	Path     string `json:"path"`
	Type     string `json:"type"`
}

Jump to

Keyboard shortcuts

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