definitions

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const SpecVersion int = 1

Variables

This section is empty.

Functions

func ValidateDefinition

func ValidateDefinition(definition *Endpoint) error

ValidateDefinition validates the definition and adds sensible defaults if needed

Types

type Endpoint

type Endpoint struct {
	Version            int               `json:"version" yaml:"version"`                                            // Version is the version of the definition
	FileName           string            `yaml:"-" json:"-"`                                                        // FileName is the name of the file that contains the definition
	FullPath           string            `yaml:"-" json:"-"`                                                        // FullPath is the full path of the file that contains the definition
	Secrets            map[string]any    `yaml:"-" json:"-"`                                                        // Secrets are the secrets for this definition loaded from the secrets file
	IsEnabled          bool              `yaml:"-" json:"-"`                                                        // IsEnabled is a boolean that indicates if the endpoint is enabled (not contained in the definition)
	Name               string            `yaml:"name,omitempty" json:"name,omitempty" validate:"required"`          // Name is the name of the endpoint
	BaseUrl            string            `yaml:"base_url,omitempty" json:"baseUrl,omitempty" validate:"required"`   // BaseUrl is the base path of the endpoint
	Method             string            `yaml:"method,omitempty" json:"method,omitempty"`                          // Method is the name of the http-method to use for the request
	Payload            map[string]any    `yaml:"payload,omitempty" json:"payload,omitempty"`                        // Payload is the payload to use in case of a POST or PUT request
	Authorization      string            `yaml:"authorization,omitempty" json:"authorization,omitempty"`            // Authorization is the value to set for the authorization header
	JwtLogin           JwtLoginOptions   `yaml:"jwt_login,omitempty" json:"jwt_login,omitempty"`                    // JwtLogin are options to auto-get a login token for a request.
	Headers            map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`                        // Headers are additional headers to set for the request
	ExcludedValidators []string          `yaml:"excluded_validators,omitempty" json:"excludedValidators,omitempty"` // ExcludedValidators is a list of validators that should not be used for this endpoint
	QueryParameters    []QueryDefinition `yaml:"query_parameters,omitempty" json:"queryParameters,omitempty"`       // QueryParameters are all the query parameters that should be added to the call
	Format             string            `yaml:"format,omitempty" json:"format,omitempty" validate:"required"`      // Format is the response format of the
	Variables          []Variable        `yaml:"variables,omitempty" json:"variables,omitempty"`                    // Variables are all the variables that should be interpolated in the base url and the query parameters
	TestCaseNames      []string          `yaml:"test_case_names,omitempty" json:"test_case_names,omitempty"`
	OkCode             int               `yaml:"ok_code,omitempty" json:"ok_code,omitempty"`                                    // The expected status code
	ResponseSchema     any               `yaml:"response_schema,omitempty" json:"responseSchema,omitempty" validate:"required"` // ResponseSchema describes how the response should look like
}

Endpoint is the definition of an endpoint to test with all its query parameters, variables and its result schema

func Endpoints

func Endpoints() ([]Endpoint, error)

Endpoints uses parseDefinition to parse all the definitions found in the definitions/ directory. Directories and Files that start with the ignorePrefix are ignored.

type JwtLoginOptions

type JwtLoginOptions struct {
	Url          string         `yaml:"url" json:"url" validate:"required"`   // Url is the url to the login endpoint
	LoginPayload map[string]any `yaml:"login_payload" json:"login_payload"`   // LoginPayload is the json or yml payload to send
	TokenKeyName string         `yaml:"token_key_name" json:"token_key_name"` // TokenKeyName is the name of the key in the response which contains the token
}

JwtLoginOptions is the definition of optional authentication options for jwt

type QueryDefinition

type QueryDefinition struct {
	Name  string `yaml:"name" json:"name" validate:"required"`   // Name is the name of the query parameter
	Value string `yaml:"value" json:"value" validate:"required"` // Value is the value of the query parameter
}

QueryDefinition is a query parameter that should be added to the call

type Variable

type Variable struct {
	Name       string   `yaml:"name" json:"name" validate:"required"`         // Name is the name of the variable
	IsConstant bool     `yaml:"constant" json:"constant" validate:"required"` // IsConstant is true if the value of the variable is constant or else false
	Values     []string `yaml:"values" json:"values" validate:"required"`     // Values are all the possible values of the variable (only 1 in case of a constant)
}

Variable describes a variable that should be interpolated in the base url and the query parameters

func (Variable) Value

func (v Variable) Value(index int) any

Value returns the value of the variable according to the index of the test case

type VariableMap

type VariableMap map[string]any

VariableMap is a map of variables that will be generated from a collection of EndpointParameter and will be used when executing the go template

func (VariableMap) Env

func (m VariableMap) Env(key string) string

Env is a function that returns the value of a given environment variable

func (VariableMap) Now

func (m VariableMap) Now(format string) string

Now is a function that returns the current time in the given format (see Time.Format)

Jump to

Keyboard shortcuts

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