client

package
v0.0.0-...-02468db Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

* Copyright Skyramp Authors 2024

* Copyright Skyramp Authors 2024

* Copyright Skyramp Authors 2024

* Copyright Skyramp Authors 2024

* Copyright Skyramp Authors 2024

* Copyright Skyramp Authors 2024

Index

Constants

View Source
const DefaultDeployTime = 3 * time.Second
View Source
const RequirementPath = "requirements.txt"

Variables

This section is empty.

Functions

func LoadCustomImageInKind

func LoadCustomImageInKind(img string, clusterName string) error

func NewGrpcEndpoint

func NewGrpcEndpoint(name, grpcServiceName string, protoFile, address string, serviceOption *types.Service) *types.EndpointDescription

NewGrpcEndpoint creates a new grpc endpoint name: the name of the endpoint grpcServiceName: the name of the grpc service protoFile: the path of the proto file address: the address of the service serviceOption: the service option return: the endpoint description

func NewRestEndpoint

func NewRestEndpoint(name, path, openApiFile string, serviceOption *types.Service) *types.EndpointDescription

NewRestEndpoint creates a new REST endpoint name: the name of the endpoint path: the path of the REST endpoint openApiFile: the path of the openapi file address: the address of the service serviceOption: the service option

Types

type Client

type Client interface {
	// InstallWorker installs the worker in the client's environment.
	// It returns an error if the worker installation fails.
	InstallWorker() error

	// UninstallWorker uninstalls the worker in the client's environment.
	// It returns an error if the worker uninstallation fails.
	UninstallWorker() error

	// TesterStart starts the test in the client's environment.
	// It takes the test scenario, test name, global variables, and global headers as parameters.
	// It returns an error if the test fails to start.
	TesterStart(scenario []*Scenario, testName string, globalVars map[string]interface{}, globalHeaders map[string]string) (*types.TestStatusResponse, error)

	// MockerApply applies the mock in the client's environment.
	// It takes the response values and traffic configuration as parameters.
	// It returns an error if the mock fails to apply.
	MockerApply(response []*ResponseValue, trafficConfig *types.TrafficConfig) error

	// TestStatus returns the status of the test in the client's environment.
	// It returns the test status response.
	TestStatus(testId string) *types.TestStatusResponse

	// SetWorkerImage overrides the default worker image.
	// It takes the image and tag as parameters.
	SetWorkerImage(image, tag string)

	// GetTestConfig returns the test configuration.
	GetTestConfig() *TestConfig

	// Cleanup uninstalls the worker in the client's environment.
	Cleanup()
}

Client represents an interface for interacting with Skyramp.

func NewClient

func NewClient(config *Config) (Client, error)

type Config

type Config struct {
	WorkerAddress string
	ScenarioName  string
	TestName      string
	K8sConfigPath string
	K8sContext    string
	ClusterName   string
	Namespace     string
	WorkerPort    int
	DeployWorker  bool
	GlobalVars    map[string]interface{}
}

func ParseArgs

func ParseArgs() (*Config, error)

ParseArgs parses the command line arguments and returns the configuration.

type DockerClient

type DockerClient struct {
	// Address is the Skyramp worker's daemon address.
	Address string

	// NetworkName is the name of the Docker network where the Skyramp worker gets installed.
	NetworkName string

	// HostPort is the port to be used by the Skyramp worker.
	HostPort int

	// WorkerImageRepo is the repository for the worker image.
	WorkerImageRepo string

	// WorkerImageTag is the tag associated with the worker image.
	WorkerImageTag string

	// TestConfig is the test configuration for the client.
	TestConfig *TestConfig
}

DockerClient represents a client configuration for interacting with Docker.

func NewDockerClient

func NewDockerClient(address, targetNetworkName string, testConfig *TestConfig) (*DockerClient, error)

NewDockerClient creates a new Docker client. It takes the address, target network name, and host port as parameters.

func (*DockerClient) Cleanup

func (c *DockerClient) Cleanup()

func (*DockerClient) GetTestConfig

func (c *DockerClient) GetTestConfig() *TestConfig

func (*DockerClient) GetTesterStatus

func (c *DockerClient) GetTesterStatus(testId string) (*types.TestStatusResponse, int, error)

GetTesterStatus returns the status of the test in the docker environment. It returns the test status response, status code, and error.

func (*DockerClient) InstallWorker

func (c *DockerClient) InstallWorker() error

InstallWorker installs the worker in the docker environment. It returns an error if the worker installation fails.

func (*DockerClient) MockerApply

func (c *DockerClient) MockerApply(response []*ResponseValue, trafficConfig *types.TrafficConfig) error

func (*DockerClient) SetWorkerImage

func (c *DockerClient) SetWorkerImage(image, tag string)

SetWorkerImage overrides the default worker image. It takes the image and tag as parameters.

func (*DockerClient) TestStatus

func (c *DockerClient) TestStatus(testId string) *types.TestStatusResponse

TestStatus returns the status of the test in the docker environment. It returns the test status response.

func (*DockerClient) TesterStart

func (c *DockerClient) TesterStart(
	scenario []*Scenario,
	testName string,
	globalVars map[string]interface{},
	globalHeaders map[string]string,
) (*types.TestStatusResponse, error)

TesterStart starts the test in the docker environment. It takes the test scenario, test name, global variables, and global headers as parameters. It returns an error if the test fails to start.

func (*DockerClient) UninstallWorker

func (c *DockerClient) UninstallWorker() error

UninstallWorker uninstalls the worker in the docker environment. It returns an error if the worker uninstallation fails.

type KubernetesClient

type KubernetesClient struct {
	// KubeconfigPath is the path to the kubeconfig file
	KubeconfigPath string
	// K8sContext is the context to use
	K8sContext string
	// ClusterName is the name of the cluster
	ClusterName string
	// Namespace is the namespace to use
	Namespace string
	// WorkerImageRepo is the repository of the worker image
	WorkerImageRepo string
	// WorkerImageTag is the tag of the worker image
	WorkerImageTag string

	// TestConfig is the test configuration for the client.
	TestConfig *TestConfig
}

KubernetesClient is a client for interacting with Kubernetes

func NewKubernetesClient

func NewKubernetesClient(kubeconfigPath, k8sContext, clusterName, namespace string, testConfig *TestConfig) (*KubernetesClient, error)

NewKubernetesClient creates a new Kubernetes client

func (*KubernetesClient) Cleanup

func (k *KubernetesClient) Cleanup()

func (*KubernetesClient) GetTestConfig

func (k *KubernetesClient) GetTestConfig() *TestConfig

func (*KubernetesClient) GetTesterStatus

func (k *KubernetesClient) GetTesterStatus(testId string) (*types.TestStatusResponse, int, error)

func (*KubernetesClient) InstallWorker

func (k *KubernetesClient) InstallWorker() error

InstallWorker installs the Skyramp worker on the Kubernetes cluster

func (*KubernetesClient) MockerApply

func (k *KubernetesClient) MockerApply(response []*ResponseValue, trafficConfig *types.TrafficConfig) error

MockerApply applies the given mocks to the Kubernetes cluster It takes the response values and traffic configuration as parameters. It returns an error if the mock fails to apply.

func (*KubernetesClient) SetWorkerImage

func (k *KubernetesClient) SetWorkerImage(image, tag string)

SetWorkerImage used for using custom worker image

func (*KubernetesClient) TestStatus

func (k *KubernetesClient) TestStatus(testId string) *types.TestStatusResponse

TestStatus returns the status of the tests on the Kubernetes cluster It returns the status of the tests.

func (*KubernetesClient) TesterStart

func (k *KubernetesClient) TesterStart(
	scenario []*Scenario,
	testName string,
	globalVars map[string]interface{},
	globalHeaders map[string]string,
) (*types.TestStatusResponse, error)

TesterStart starts the tests on the Kubernetes cluster It takes the scenario, test name, global variables, and global headers as parameters. It returns an error if the tests fail to start.

func (*KubernetesClient) UninstallWorker

func (k *KubernetesClient) UninstallWorker() error

UninstallWorker uninstalls the Skyramp worker from the Kubernetes cluster

type Request

type Request struct {
	*types.TestRequest
	EndpointDescription *types.EndpointDescription
}

func NewRequest

func NewRequest(name string, endpointDesc *types.EndpointDescription, methodName, blob string) *Request

func (*Request) SetCookies

func (r *Request) SetCookies(cookies map[string]string)

func (*Request) SetGraphqlQuery

func (r *Request) SetGraphqlQuery(query *types.GraphqlParam) error

func (*Request) SetHeader

func (r *Request) SetHeader(header map[string]string)

func (*Request) SetJSFunction

func (r *Request) SetJSFunction(jsFunction, jsPath string) error

func (*Request) SetParams

func (r *Request) SetParams(params []*types.RestParam)

func (*Request) SetPythonFunction

func (r *Request) SetPythonFunction(pythonFunction, pythonPath string) error

func (*Request) SetVars

func (r *Request) SetVars(vars map[string]interface{})

type ResponseValue

type ResponseValue struct {
	*types.Response
	TrafficConfig       *types.TrafficConfig
	EndpointDescription *types.EndpointDescription
}

func NewResponseValue

func NewResponseValue(name string, endpointDesc *types.EndpointDescription, methodName, blob string, trafficConfig *types.TrafficConfig) *ResponseValue

func (*ResponseValue) SetCookies

func (r *ResponseValue) SetCookies(cookies map[string]string)

func (*ResponseValue) SetHeader

func (r *ResponseValue) SetHeader(header map[string]string)

func (*ResponseValue) SetJSFunction

func (r *ResponseValue) SetJSFunction(jsFunction, jsPath string) error

func (*ResponseValue) SetParams

func (r *ResponseValue) SetParams(params []*types.RestParam)

func (*ResponseValue) SetPythonFunction

func (r *ResponseValue) SetPythonFunction(pythonFunction, pythonPath string) error

type Scenario

type Scenario struct {
	TestScenario        *types.TestScenario
	Requests            []*Request
	EndpointDescription *types.EndpointDescription
}

func NewScenario

func NewScenario(name string) *Scenario

func (*Scenario) SetAssertEqual

func (s *Scenario) SetAssertEqual(str1, str2 string)

func (*Scenario) SetRequest

func (s *Scenario) SetRequest(request *Request) *types.TestStep

type StringList

type StringList []string

func (*StringList) Set

func (s *StringList) Set(value string) error

func (StringList) String

func (s StringList) String() string

type TestConfig

type TestConfig struct {
	// ScenarioName is the name of the scenario to be executed.
	ScenarioName string
	// TestName is the name of the test to be executed.
	TestName string
	// GlobalVars are the global variables to be used in the test.
	GlobalVars map[string]interface{}
	// DeployWorker is a flag to indicate if the worker should be installed.
	DeployWorker bool
}

TestConfig represents the configuration for a test.

Jump to

Keyboard shortcuts

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