httpscenario

package
v0.5.17 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Example (EncodeAmmoHCLVariablesSources)
app := AmmoHCL{
	VariableSources: []SourceHCL{
		{
			Type:   "file/csv",
			Name:   "user_srs",
			File:   pointer.ToString("users.json"),
			Fields: &([]string{"id", "name", "email"}),
		},
		{
			Type:   "file/json",
			Name:   "data_srs",
			File:   pointer.ToString("datas.json"),
			Fields: &([]string{"id", "name", "email"}),
		},
	},
}

f := hclwrite.NewEmptyFile()
gohcl.EncodeIntoBody(&app, f.Body())
bytes := f.Bytes()
fmt.Printf("%s", bytes)
Output:


variable_source "user_srs" "file/csv" {
  file   = "users.json"
  fields = ["id", "name", "email"]
}
variable_source "data_srs" "file/json" {
  file   = "datas.json"
  fields = ["id", "name", "email"]
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(fs afero.Fs)

func NewProvider

func NewProvider(fs afero.Fs, conf Config) (core.Provider, error)

func RegisterPostprocessor

func RegisterPostprocessor(name string, mwConstructor interface{}, defaultConfigOptional ...interface{})

func RegisterTemplater

func RegisterTemplater(name string, mwConstructor interface{}, defaultConfigOptional ...interface{})

func RegisterVariableSource

func RegisterVariableSource(name string, mwConstructor interface{}, defaultConfigOptional ...interface{})

Types

type Ammo

type Ammo struct {
	Requests []Request
	// contains filtered or unexported fields
}

func (*Ammo) GetMinWaitingTime

func (a *Ammo) GetMinWaitingTime() time.Duration

func (*Ammo) ID

func (a *Ammo) ID() uint64

func (*Ammo) Name

func (a *Ammo) Name() string

func (*Ammo) Sources

func (a *Ammo) Sources() httpscenario.VariableStorage

func (*Ammo) Steps

func (a *Ammo) Steps() []httpscenario.Step

type AmmoConfig

type AmmoConfig struct {
	VariableSources []VariableSource `config:"variable_sources"`
	Requests        []RequestConfig
	Scenarios       []ScenarioConfig
}

func ConvertHCLToAmmo

func ConvertHCLToAmmo(ammo AmmoHCL, fs afero.Fs) (AmmoConfig, error)

func ParseAmmoConfig

func ParseAmmoConfig(file io.Reader) (AmmoConfig, error)

type AmmoHCL

type AmmoHCL struct {
	VariableSources []SourceHCL   `hcl:"variable_source,block"`
	Requests        []RequestHCL  `hcl:"request,block"`
	Scenarios       []ScenarioHCL `hcl:"scenario,block"`
}

func ConvertAmmoToHCL

func ConvertAmmoToHCL(ammo AmmoConfig) (AmmoHCL, error)

func ParseHCLFile

func ParseHCLFile(file afero.File) (AmmoHCL, error)

type AssertSizeHCL

type AssertSizeHCL struct {
	Val *int    `hcl:"val"`
	Op  *string `hcl:"op"`
}

type Config

type Config struct {
	File            string
	Limit           uint
	Passes          uint
	ContinueOnError bool
	MaxAmmoSize     int
}

type HTMLTemplater

type HTMLTemplater struct {
	// contains filtered or unexported fields
}

func (*HTMLTemplater) Apply

func (t *HTMLTemplater) Apply(parts *httpscenario.RequestParts, vs map[string]any, scenarioName, stepName string) error

type PostprocessorHCL

type PostprocessorHCL struct {
	Type       string             `hcl:"type,label"`
	Mapping    *map[string]string `hcl:"mapping"`
	Headers    *map[string]string `hcl:"headers"`
	Body       *[]string          `hcl:"body"`
	StatusCode *int               `hcl:"status_code"`
	Size       *AssertSizeHCL     `hcl:"size,block"`
}

type Preprocessor

type Preprocessor struct {
	Mapping map[string]string
	// contains filtered or unexported fields
}

func (*Preprocessor) Process

func (p *Preprocessor) Process(templateVars map[string]any) (map[string]any, error)

type PreprocessorHCL

type PreprocessorHCL struct {
	Mapping map[string]string `hcl:"mapping"`
}

type Provider

type Provider struct {
	base.ProviderBase
	// contains filtered or unexported fields
}

func (*Provider) Acquire

func (p *Provider) Acquire() (core.Ammo, bool)

func (*Provider) Release

func (p *Provider) Release(_ core.Ammo)

func (*Provider) Run

func (p *Provider) Run(ctx context.Context, deps core.ProviderDeps) error

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) GetBody

func (r *Request) GetBody() []byte

func (*Request) GetHeaders

func (r *Request) GetHeaders() map[string]string

func (*Request) GetMethod

func (r *Request) GetMethod() string

func (*Request) GetName

func (r *Request) GetName() string

func (*Request) GetPostProcessors

func (r *Request) GetPostProcessors() []httpscenario.Postprocessor

func (*Request) GetSleep

func (r *Request) GetSleep() time.Duration

func (*Request) GetTag

func (r *Request) GetTag() string

func (*Request) GetTemplater

func (r *Request) GetTemplater() httpscenario.Templater

func (*Request) GetURL

func (r *Request) GetURL() string

func (*Request) Preprocessor

func (r *Request) Preprocessor() httpscenario.Preprocessor

type RequestConfig

type RequestConfig struct {
	Name           string
	Method         string
	Headers        map[string]string
	Tag            string
	Body           *string
	URI            string
	Preprocessor   Preprocessor
	Postprocessors []postprocessor.Postprocessor
	Templater      Templater
}

type RequestHCL

type RequestHCL struct {
	Name           string             `hcl:"name,label"`
	Method         string             `hcl:"method"`
	Headers        map[string]string  `hcl:"headers"`
	Tag            *string            `hcl:"tag"`
	Body           *string            `hcl:"body"`
	URI            string             `hcl:"uri"`
	Preprocessor   *PreprocessorHCL   `hcl:"preprocessor,block"`
	Postprocessors []PostprocessorHCL `hcl:"postprocessor,block"`
	Templater      *string            `hcl:"templater"`
}

type ScenarioConfig

type ScenarioConfig struct {
	Name           string
	Weight         int64
	MinWaitingTime int64 `config:"min_waiting_time"`
	Requests       []string
}

type ScenarioHCL

type ScenarioHCL struct {
	Name           string   `hcl:"name,label"`
	Weight         *int64   `hcl:"weight"`
	MinWaitingTime *int64   `hcl:"min_waiting_time"`
	Requests       []string `hcl:"requests"`
}

type SourceHCL

type SourceHCL struct {
	Name            string             `hcl:"name,label"`
	Type            string             `hcl:"type,label"`
	File            *string            `hcl:"file"`
	Fields          *[]string          `hcl:"fields"`
	IgnoreFirstLine *bool              `hcl:"ignore_first_line"`
	Delimiter       *string            `hcl:"delimiter"`
	Variables       *map[string]string `hcl:"variables"`
}

type SourceStorage

type SourceStorage struct {
	// contains filtered or unexported fields
}

func (*SourceStorage) AddSource

func (s *SourceStorage) AddSource(name string, variables any)

func (*SourceStorage) Variables

func (s *SourceStorage) Variables() map[string]any

type Templater

type Templater interface {
	Apply(request *httpscenario.RequestParts, variables map[string]any, scenarioName, stepName string) error
}

func NewHTMLTemplater

func NewHTMLTemplater() Templater

func NewTextTemplater

func NewTextTemplater() Templater

type TextTemplater

type TextTemplater struct {
	// contains filtered or unexported fields
}

func (*TextTemplater) Apply

func (t *TextTemplater) Apply(parts *httpscenario.RequestParts, vs map[string]any, scenarioName, stepName string) error

type VariableSource

type VariableSource interface {
	GetName() string
	GetVariables() any
	Init() error
}

func NewVSCSV

func NewVSCSV(cfg VariableSourceCsv, fs afero.Fs) (VariableSource, error)

func NewVSJson

func NewVSJson(cfg VariableSourceJSON, fs afero.Fs) (VariableSource, error)

type VariableSourceCsv

type VariableSourceCsv struct {
	Name            string
	File            string
	Fields          []string
	IgnoreFirstLine bool `config:"ignore_first_line"`
	Delimiter       string
	// contains filtered or unexported fields
}

func (*VariableSourceCsv) GetName

func (v *VariableSourceCsv) GetName() string

func (*VariableSourceCsv) GetVariables

func (v *VariableSourceCsv) GetVariables() any

func (*VariableSourceCsv) Init

func (v *VariableSourceCsv) Init() (err error)

type VariableSourceJSON

type VariableSourceJSON struct {
	Name string
	File string
	// contains filtered or unexported fields
}

func (*VariableSourceJSON) GetName

func (v *VariableSourceJSON) GetName() string

func (*VariableSourceJSON) GetVariables

func (v *VariableSourceJSON) GetVariables() any

func (*VariableSourceJSON) Init

func (v *VariableSourceJSON) Init() (err error)

type VariableSourceVariables

type VariableSourceVariables struct {
	Name      string
	Variables map[string]any
}

func (*VariableSourceVariables) GetName

func (v *VariableSourceVariables) GetName() string

func (*VariableSourceVariables) GetVariables

func (v *VariableSourceVariables) GetVariables() any

func (*VariableSourceVariables) Init

func (v *VariableSourceVariables) Init() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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