Documentation
¶
Overview ¶
Package monax represents the public Monax API.
Index ¶
- Constants
- Variables
- func DHCPSelector(serviceName string) func(*monaxpb.Interface) bool
- func GRPCSelector(serviceName string) func(*monaxpb.Interface) bool
- func HTTPSSelector(serviceName string) func(*monaxpb.Interface) bool
- func HTTPSelector(serviceName string) func(*monaxpb.Interface) bool
- func ProcessVars(global map[string]string, local map[string]string, component *Component) (map[string]string, error)
- type Component
- type Config
- type Handler
- type NewRuntimeFn
- type Runtime
- type SUT
- type SUTError
- type SUTInterfaces
- func (i *SUTInterfaces) DHCP(ctx context.Context, serviceName string) (string, error)
- func (i *SUTInterfaces) GRPC(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func (i *SUTInterfaces) HTTP(ctx context.Context, serviceName string) (string, error)
- func (i *SUTInterfaces) HTTPS(ctx context.Context, serviceName string) (string, error)
- type SUTTargets
- func (t *SUTTargets) DHCP(ctx context.Context, serviceName string) (string, error)
- func (t *SUTTargets) GRPC(ctx context.Context, serviceName string) (string, error)
- func (t *SUTTargets) HTTP(ctx context.Context, serviceName string) (string, error)
- func (t *SUTTargets) HTTPS(ctx context.Context, serviceName string) (string, error)
- type Target
- type Targets
- type UnimplementedTargets
- func (UnimplementedTargets) DHCP(ctx context.Context, serviceName string) (Target, error)
- func (UnimplementedTargets) GRPC(ctx context.Context, serviceName string) (Target, error)
- func (UnimplementedTargets) HTTP(ctx context.Context, serviceName string) (Target, error)
- func (UnimplementedTargets) HTTPS(ctx context.Context, serviceName string) (Target, error)
Constants ¶
const ComponentIDRegex = `^[a-zA-Z][a-zA-Z0-9-_]*$`
ComponentIDRegex is the regex for a valid component ID. The ID must start with a letter, and may only contain letters, numbers, dashes, and underscores. Whitespace is not allowed due to how the CLIs and other tools parse args with spaces.
const EmptyTarget = Target("")
EmptyTarget represents an empty target.
Variables ¶
var ( // ErrDuplicateInterfaceDefinitions indicates the library is invalid because // it contains a component with duplicate interface definitions. ErrDuplicateInterfaceDefinitions = errors.New("duplicate interface definitions") // ErrProvidedInterface indicates that an error was received from the // component handler when trying to retrieve a provided interface. ErrProvidedInterface = errors.New("retrieving provided interface") // ErrUnknownRequiredInterfaceName indicates that the required interface name // could not be found in the component's required interfaces. ErrUnknownRequiredInterfaceName = errors.New("unknown required interface name") // ErrInvalidComponentID indicates that the component ID in the library is // invalid. ErrInvalidComponentID = errors.New("invalid component ID") )
var ( // ErrDecodeTextproto indicates a textproto could not be decoded to a specific // protobuf message. ErrDecodeTextproto = errors.New("decode textproto") // ErrNoAbstractSUT indicates an abstract SUT was not set in the Config. ErrNoAbstractSUT = errors.New("no abstract SUT in config") // ErrNoLibrary indicates a library was not set in the Config. ErrNoLibrary = errors.New("no library in config") // ErrReadTextproto indicates a textproto file could not be read. ErrReadTextproto = errors.New("read textproto") )
var ( // ErrDialGRPCService indicates that the gRPC service could not be dialed. ErrDialGRPCService = errors.New("dial gRPC service") // ErrVerifyGRPCService indicates that the gRPC service could not be verified. ErrVerifyGRPCService = errors.New("verify gRPC service") )
var ( // ErrCyclicDependencies indicates the library is invalid because it contains // cyclic dependencies. ErrCyclicDependencies = errors.New("cyclic dependencies") // ErrDuplicateComponentDefinitions indicates the library is invalid because // it contains duplicate definitions of a component. ErrDuplicateComponentDefinitions = errors.New("duplicate component definitions") // ErrDuplicateInterfaceProviders indicates the library is invalid because it // contains duplicate providers of an interface. ErrDuplicateInterfaceProviders = errors.New("duplicate interface providers") // ErrMissingHandler indicates the library is invalid because it contains // components with no handler in the runtime. ErrMissingHandler = errors.New("missing handler") // ErrMissingRequiredInterface indicates the abstract SUT or library are // invalid because an interface required by the abstract SUT or a component in // the library is not provided by the library. ErrMissingRequiredInterface = errors.New("missing required interface") // ErrNoConfig indicates a Config was not set. ErrNoConfig = errors.New("no config") // ErrNoRequiredInterfaces indicates the abstract SUT is invalid because it // specifies no required interfaces. ErrNoRequiredInterfaces = errors.New("no required interfaces") // ErrNoNewRuntimeFn indicates a new runtime function was not set. ErrNoNewRuntimeFn = errors.New("no new runtime function") // ErrNoRuntime indicates a runtime was not returned by the new runtime // function. ErrNoRuntime = errors.New("no runtime") )
var ( // ErrAlreadyStarted indicates the SUT cannot perform an operation because it // is already started. ErrAlreadyStarted = errors.New("already started") // ErrNotStarted indicates the SUT cannot perform an operation because it is // not started. ErrNotStarted = errors.New("not started") )
var ( // ErrRequestedInterfaceNotProvided indicates that the requested interface is // not provided by the SUT because it was not specified as a required // interface of the abstract SUT. ErrRequestedInterfaceNotProvided = errors.New("requested interface not provided by the SUT") )
var ( // ErrTargetNotImplemented indicates that a handler has not implemented the // requested target retriever type. ErrTargetNotImplemented = errors.New("target not implemented") )
Functions ¶
func DHCPSelector ¶
DHCPSelector returns a function that matches a DHCP interface with the given service name.
func GRPCSelector ¶
GRPCSelector returns a function that matches a gRPC interface with the given service name.
func HTTPSSelector ¶
HTTPSSelector returns a function that matches an HTTPS interface with the given service name.
func HTTPSelector ¶
HTTPSelector returns a function that matches an HTTP interface with the given service name.
func ProcessVars ¶
func ProcessVars(global map[string]string, local map[string]string, component *Component) (map[string]string, error)
ProcessVars replaces templated strings in the local map with the appropriate values from the global or local map or the appropriate dependency target. After the template values are substituted, any strings in the resulting values like '$VAR_NAME' or '${VAR_NAME}' will be replaced with the corresponding environment variable value. Note that environment variables cannot be used within the template expressions {{ ... }} themselves.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component is an element in the SUT that satisfies direct or transitive dependencies of the abstract SUT.
func (*Component) Parameters ¶
Parameters returns the component parameters.
func (*Component) RequiredTarget ¶
RequiredTarget returns the target for the given required interface name. Required interface names are specified by the user in the component proto.
func (*Component) ResolvePath ¶
ResolvePath resolves a textproto path using the relative path information injected into the component when the library is built.
type Config ¶
type Config struct {
// An abstract SUT is a description of the high-level requirements of a test.
//
// One of AbstractSUT or AbstractSUTPath must be set in the config. If both
// are set, AbstractSUT will be used and AbstractSUTPath will be ignored.
// AbstractSUTPath is a path to a monax.AbstractSut textproto and may be set
// from the command line.
AbstractSUT *monaxpb.AbstractSut
AbstractSUTPath string
// A library contains descriptions of the components available to satisfy the
// requirements of the abstract SUT.
//
// One of Library or LibraryPath must be set in the config. If both are set,
// Library will be used and LibraryPath will be ignored. LibraryPath is a path
// to a monax.Library textproto and may be set from the command line.
Library *monaxpb.Library
LibraryPath string
// Runtime parameters are additional configuration options for the runtime.
//
// RuntimeParameters or RuntimeParametersPath may be set in the config. If
// both are set, RuntimeParameters will be used and RuntimeParametersPath will
// be ignored. RuntimeParametersPath is a path to a monax.RuntimeParameters
// and may be set from the command line.
RuntimeParameters *monaxpb.RuntimeParameters
RuntimeParametersPath string
// contains filtered or unexported fields
}
A Config contains the parameters used to create a new SUT.
The parameters can be set programmatically. Some parameters may be set with command line flags, as in the following example.
package main
var config monax.Config
func init() {
config.RegisterFlags(nil) // install the flags
}
func main() {
flag.Parse()
ctx := context.Background()
runtime := ...
sut, err := monax.New(ctx, &config, runtime)
// check err and use sut ...
}
func (*Config) RegisterFlags ¶
RegisterFlags registers command line flags that modify a Config. flag.CommandLine is used when the flag set is nil.
type Handler ¶
type Handler interface {
Initialize(ctx context.Context, component *Component) error
Start(ctx context.Context, component *Component) error
Stop(ctx context.Context, component *Component) error
Status(ctx context.Context, component *Component) error
Targets(component *Component) Targets
}
Handler is an interface for interacting with a component within the SUT.
type NewRuntimeFn ¶
NewRuntimeFn defines the function signature for creating new instances of a Runtime. It's used to allow different runtime implementations to be registered and created dynamically.
type Runtime ¶
type Runtime interface {
Initialize(parameters *monaxpb.RuntimeParameters) error
Handler(kind string) Handler
}
Runtime is an interface for runtime implementations.
type SUT ¶
type SUT struct {
// contains filtered or unexported fields
}
SUT is a system under test.
func (*SUT) Interfaces ¶
func (s *SUT) Interfaces() *SUTInterfaces
Interfaces returns a handle to the interfaces API.
func (*SUT) Start ¶
Start starts the components in the SUT. If component A depends on an interface provided by component B, A will be started only after B has started.
Returns ErrAlreadyStarted if the SUT is already started. Otherwise, returns a SUTError if any component fails to start.
Caller should stop the SUT when done with it by calling [Stop].
if err := sut.Start(ctx); err != nil {
// handle error
}
defer func() {
if err := sut.Stop(ctx); err != nil {
// handle error
}
}
If the error will be handled by exiting the program, including by log.Exit or log.Fatal, then the caller should stop the SUT prior to exiting.
if err := sut.Start(ctx); err != nil {
err = errors.Join(err, sut.Stop(ctx))
log.ExitContext(ctx, err)
}
defer func() {
if err := sut.Stop(ctx); err != nil {
// handle error
}
}
func (*SUT) Status ¶
Status gets the status of the components in the SUT.
Returns ErrNotStarted if the SUT is not started. Otherwise, returns a SUTError if any component has errors.
func (*SUT) Stop ¶
Stop stops the components in the SUT. If component A depends on an interface provided by component B, B will be stopped only after A has stopped.
If Stop fails, the SUT may need to be stopped manually. See [Start] for examples for calling Stop.
Returns ErrNotStarted if the SUT is not started. Otherwise, returns a SUTError if any component fails to stop.
func (*SUT) Targets ¶
func (s *SUT) Targets() *SUTTargets
Targets returns a handle to the targets API.
type SUTError ¶
SUTError is an aggregation of component errors.
func (*SUTError) PrettyPrint ¶
PrettyPrint returns a human readable string representation of the SUTError.
type SUTInterfaces ¶
type SUTInterfaces struct {
// contains filtered or unexported fields
}
SUTInterfaces implements methods for retrieving different kinds of interfaces from the SUT.
func (*SUTInterfaces) DHCP ¶
DHCP returns the URL of the DHCP service with the given serviceName from the SUT.
func (*SUTInterfaces) GRPC ¶
func (i *SUTInterfaces) GRPC(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
GRPC returns a connection to the gRPC service with the given serviceName from the SUT and dialed with the provided options.
type SUTTargets ¶
type SUTTargets struct {
// contains filtered or unexported fields
}
SUTTargets implements methods for retrieving different kinds of targets from the SUT.
func (*SUTTargets) DHCP ¶
DHCP returns the target of the DHCP service with the given serviceName from the SUT.
func (*SUTTargets) GRPC ¶
GRPC returns the target of the gRPC service with the given serviceName from the SUT.
type Targets ¶
type Targets interface {
DHCP(ctx context.Context, serviceName string) (Target, error)
GRPC(ctx context.Context, serviceName string) (Target, error)
HTTP(ctx context.Context, serviceName string) (Target, error)
HTTPS(ctx context.Context, serviceName string) (Target, error)
}
Targets is an interface for retrieving targets of provided interfaces in the SUT.
type UnimplementedTargets ¶
type UnimplementedTargets struct{}
UnimplementedTargets is a struct that implements Targets and returns ErrTargetNotImplemented for all target types. By embedding this struct, implementations of Targets can ignore target types that they do not support.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package monaxondatratest provides a utility function to start and stop the SUT for Monax tests within the Ondatra test lifecycle.
|
Package monaxondatratest provides a utility function to start and stop the SUT for Monax tests within the Ondatra test lifecycle. |
|
Package monaxtest provides a utility function to start the SUT for Monax tests.
|
Package monaxtest provides a utility function to start the SUT for Monax tests. |
|
Package proto contains protos for monax.
|
Package proto contains protos for monax. |
|
runtime
|
|
|
kubernetesruntime
Package kubernetesruntime is the Monax runtime for Kubernetes components.
|
Package kubernetesruntime is the Monax runtime for Kubernetes components. |
|
kubernetesruntime/proto
Package proto contains protos for the kubernetes runtime.
|
Package proto contains protos for the kubernetes runtime. |


