api

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package api implements a layer between javascript code (via goja)) and the disruptors allowing for validations and type conversions when needed

The implementation of the JS API follows the design described in https://github.com/grafana/xk6-disruptor/blob/fix-context-usage/docs/01-development/design-docs/002-js-api-implementation.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert added in v0.3.0

func Convert(value interface{}, target interface{}) error

Convert converts from a generic object received from the JS interface via goja into a go type. It supports the following conversions: Target golang value Value from JS struct <-- map[string]interface{} map[string]ValueType <-- map[string]interface (1) []type <-- []interface{} float64 <-- float64 int64 <-- int64 string <-- string time.Duration <-- string time.Time <-- string (only in RFC3339 format)

(1) TODO: support other key types, such as numeric and attempt conversion from the string key

func IsCompatible

func IsCompatible(actual interface{}, expected interface{}) error

IsCompatible checks if the actual value can be assigned to a variable of the expected type For Slices it expects []interface{} and therefore cannot check the type of the elements. For Maps it expects map[string]interface{} and therefore cannot check the type of the elements

func NewPodDisruptor

func NewPodDisruptor(
	ctx context.Context,
	rt *goja.Runtime,
	c goja.ConstructorCall,
	k8s kubernetes.Kubernetes,
) (*goja.Object, error)

NewPodDisruptor creates an instance of a PodDisruptor The context passed to this constructor is expected to control the lifecycle of the PodDisruptor

func NewServiceDisruptor

func NewServiceDisruptor(
	ctx context.Context,
	rt *goja.Runtime,
	c goja.ConstructorCall,
	k8s kubernetes.Kubernetes,
) (*goja.Object, error)

NewServiceDisruptor creates an instance of a ServiceDisruptor and returns it as a goja object The context passed to this constructor is expected to control the lifecycle of the ServiceDisruptor

func ValidateStruct

func ValidateStruct(actual interface{}, expected interface{}) error

ValidateStruct validates that the value of a generic map[string]interface{} can be assigned to a expected Struct using the compatibility rules defined in IsCompatible. Note that the field names are expected to match except for the case of the initial letter e.g 'fieldName' will match 'FieldName' in the struct, but 'field_name' will not.

TODO: use the tags in the struct to find out any field name mapping. This will require iterating from the struct to the actual value. This will not detect spurious fields in the actual value

Types

This section is empty.

Jump to

Keyboard shortcuts

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