internal

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendHostsFile

func AppendHostsFile(content string) error

AppendHostsFile appends a string to /etc/hosts as a new line

func ApplyConfig

func ApplyConfig(config *Config) error

ApplyConfig applies config

func PrintTestResult

func PrintTestResult(test *Test, result *TestResult)

PrintTestResult prints result of a single test

func PrintTestSummary

func PrintTestSummary(passed, failed, skipped int)

PrintTestSummary prints summary info for multiple tests

func ProcessDynamicHeaders

func ProcessDynamicHeaders(dynamicHeaders []DynamicHeader, allHeaders map[string]string) error

ProcessDynamicHeaders creates headers based on the function and adds them to the map of all headers.

func RunTests

func RunTests(tests []*Test, config *Config) bool

RunTests runs all tests

func SendHTTPRequest

func SendHTTPRequest(config *HTTPRequestConfig) (*http.Response, []byte, error)

SendHTTPRequest sends an HTTP request and returns response body and status

Types

type Config

type Config struct {
	Concurrency          int
	DNSOverride          string
	Host                 string
	PrintFailedTestsOnly bool
	TestDirectory        string
	Verbosity            int
	EnableRetries        bool
	RetryCount           int
}

Config stores application configuration

func FromEnv

func FromEnv() (*Config, error)

FromEnv returns config read from environment variables

type DynamicHeader

type DynamicHeader struct {
	Name     string   `yaml:"name"`
	Function string   `yaml:"function"`
	Args     []string `yaml:"args,omitempty"`
}

type HTTPRequestConfig

type HTTPRequestConfig struct {
	Method               string
	URL                  string
	QueryParams          map[string]string
	Headers              map[string]string
	BasicAuthUsername    string
	BasicAuthPassword    string
	Body                 io.Reader
	TimeoutSeconds       time.Duration
	SkipCertVerification bool
	MaxRetries           int
	RetryCallback        func(ctx context.Context, resp *http.Response, err error) (bool, error)
}

HTTPRequestConfig type

type Test

type Test struct {
	Filename    string
	Description string
	Conditions  struct {
		Env map[string]string `yaml:"env"`
	} `yaml:"conditions"`
	SkipCertVerification bool `yaml:"skipCertVerification"`
	Request              struct {
		Scheme         string            `yaml:"scheme"`
		Host           string            `yaml:"host"`
		Method         string            `yaml:"method"`
		Path           string            `yaml:"path"`
		Headers        map[string]string `yaml:"headers"`
		DynamicHeaders []DynamicHeader   `yaml:"dynamicHeaders"`
		Body           string            `yaml:"body"`
	} `yaml:"request"`
	Response struct {
		StatusCodes []int `yaml:"statusCodes"`
		Headers     struct {
			Patterns             map[string]string `yaml:"patterns"`
			NotPresent           []string          `yaml:"notPresent"`
			NotMatching          map[string]string `yaml:"notMatching"`
			IfPresentNotMatching map[string]string `yaml:"ifPresentNotMatching"`
		} `yaml:"headers"`
		Body struct {
			Patterns []string `yaml:"patterns"`
		}
	} `yaml:"response"`
}

Test is a single test

func ParseAllTestsInDirectory

func ParseAllTestsInDirectory(root string) ([]*Test, error)

ParseAllTestsInDirectory recursively parses all test definition files in a given directory

type TestFile

type TestFile struct {
	Tests []*Test `yaml:"tests"`
}

TestFile is a single test definition file

type TestResult

type TestResult struct {
	Skipped bool
	Errors  []error
}

TestResult stores results of a single test

func RunTest

func RunTest(test *Test, defaultHost string, maxRetries int) *TestResult

RunTest runs a single test

Jump to

Keyboard shortcuts

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