test

package
v0.0.0-...-64e7420 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKeyAuthInfo

type ApiKeyAuthInfo struct {
	HeaderName string `json:"header"`
	ApiKey     string `json:"api_key"`
}

ApiKeyAuthInfo is the configuration for API key authentication

type Client

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

Client is a very generic http client for making requests to url patterns

func NewClient

func NewClient(baseURL string) *Client

func (*Client) Debug

func (c *Client) Debug() *Client

Debug activates debugging calls

func (*Client) Do

func (c *Client) Do(method, pathPattern string, vars map[string]string, body any) (resp *http.Response, err error)

Do makes an HTTP request to the path pattern, with the vars context and body with a JSON body method is the verb of the request. Ex: GET, POST, PUT, DELETE pathPattern is a path pattern with variables in the form of {var_name}. Ex: /orders/{order_id} vars is a map of variables to be applied to the path pattern. Ex: map[string]string{"order_id": "123"}

func (*Client) WithAuth

func (c *Client) WithAuth(auth *ApiKeyAuthInfo) *Client

WithAuth adds authentication information to the client

func (*Client) WithNoAuth

func (c *Client) WithNoAuth() *Client

func (*Client) WithOAuth2

func (c *Client) WithOAuth2(auth *OAuth2Info) *Client

WithOAuth2 sets up OAuth2 authentication information to the client

type Config

type Config struct {
	// BaseURL is the host or host + fixed part of the path (for every method)
	BaseURL string `json:"base_url"`
	// ApiKeyAuth is the authentication information for Api Key authentication
	ApiKeyAuth *ApiKeyAuthInfo `json:"auth"`
	// OAuth2Info is the authentication information for OAuth2 authentication
	OAuth2Info *OAuth2Info `json:"oauth2"`
	// Tests is the configuration of tests to run
	Tests []Test `json:"tests"`
	// Debug the requests/responses
	Debug bool `json:"debug"`
}

Config is the configuration of the suite of tests

func NewConfig

func NewConfig(path string) (*Config, error)

func (*Config) Test

func (c *Config) Test(method string) *Test

Test finds a test by method name

type JsonValidator

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

func NewJsonValidator

func NewJsonValidator(jsonSchemaPath string) (*JsonValidator, error)

func (*JsonValidator) RequireModel

func (v *JsonValidator) RequireModel(t *testing.T, model string, data []byte)

func (*JsonValidator) Validate

func (v *JsonValidator) Validate(model string, data []byte) error

type OAuth2Info

type OAuth2Info struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	// Url or Path in where the API is serving the OAuth2 token generation endpoint
	TokenUrl  string   `json:"token_url"`
	Scopes    []string `json:"scopes"`
	GrantType string   `json:"grant_type"`
}

OAuth2Info is the configuration for OAuth2 authentication

type Scenario

type Scenario struct {
	Name                   string `json:"name"`
	CustomerPrintedOrderId string `json:"customer_printed_order_id"`
	OrderID                string `json:"order_id"`
	ReturnID               string `json:"return_id"`
}

func (*Scenario) Vars

func (s *Scenario) Vars() map[string]string

type Test

type Test struct {
	Method     string     `json:"method"`
	UrlPattern string     `json:"url_pattern"`
	Scenarios  []Scenario `json:"scenarios"`
}

func (*Test) FailTestIfScenarioNotPresent

func (t *Test) FailTestIfScenarioNotPresent(tt *testing.T, scenarioName string)

FailTestIfScenarioNotPresent requires the test config to be present

func (*Test) Scenario

func (t *Test) Scenario(name string) *Scenario

Scenario finds a scenario by name

func (*Test) SkipTestIfScenarioNotPresent

func (t *Test) SkipTestIfScenarioNotPresent(tt *testing.T, scenarioName string)

SkipIfNotPresent skips the test if the scenario is not present in the config

Jump to

Keyboard shortcuts

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