http

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: BSD-3-Clause Imports: 18 Imported by: 5

README

Venom - Executor HTTP

Step for execute a HTTP Request

Input

In your yaml file, you can use:

  - method optional, default value: GET
  - url mandatory
  - unix_sock optional
  - path optional
  - body optional
  - bodyFile optional
  - headers optional
  - proxy optional: set to use a proxy server for connection to url
  - ignore_verify_ssl optional: set to true if you use a self-signed SSL on remote for example
  - basic_auth_user optional: username to use for HTTP basic authentification
  - basic_auth_password optional: password to use for HTTP basic authentification
  - no_follow_redirect optional: indicates that you don't want to follow Location if server returns a Redirect (301/302/...)
  - skip_body: skip the body and bodyjson result
  - skip_headers: skip the headers result


name: Title of TestSuite
testcases:

- name: GET http testcase
  steps:
  - type: http
    method: GET
    url: https://eu.api.ovh.com/1.0/
    assertions:
    - result.body ShouldContainSubstring /dedicated/server
    - result.body ShouldContainSubstring /ipLoadbalancing
    - result.statuscode ShouldEqual 200
    - result.bodyjson.apis.apis0.path ShouldEqual /allDom


- name: POST http with bodyFile
  steps:
  - type: http
    method: POST
    url: https://eu.api.ovh.com/1.0/
    bodyFile: /tmp/myfile.tmp
    assertions:
    - result.statuscode ShouldNotEqual 200


- name: POST http with multipart
  steps:
  - type: http
    method: POST
    url: https://eu.api.ovh.com/1.0/
    multipart_form:
        file: '@/tmp/myfile.tmp'
    assertions:
    - result.statuscode ShouldNotEqual 200

- name: GET API health over Unix Socket
  steps:
  - type: http
    method: GET
    unix_sock: /run/myapp/health.sock
    url: http://unix/health
    assertions:
    - result.bodyjson.success ShouldBeTrue

NB: to post a file with multipart_form, prefix the path to the file with '@'

Output

result.executor
result.timeseconds
result.timehuman
result.statuscode
result.body
result.bodyjson
result.headers
result.error
  • result.timeseconds & result.timehuman: time of execution
  • result.executor.executor.method: HTTP method used, example: GET
  • result.executor.executor.url: url called
  • result.executor.executor.multipartform: multipartform if exists
  • result.err: if exists, this field contains error
  • result.body: body of HTTP response
  • result.bodyjson: body of HTTP response if it's a JSON. You can access json data as result.bodyjson.yourkey for example.
  • result.headers: headers of HTTP response
  • result.statuscode: Status Code of HTTP response
JSON keys

JSON keys are lowercased automatically (eg. use result.bodyjson.yourkey, not result.bodyjson.YourKey).

On top of that, if a JSON key contains special characters, they will be translate to underscores.

JSON arrays

When a HTTP response contains a JSON array, you have to use following syntax to access specific key of an array: result.bodyjson.array_name.array_name_index_in_array.key

Example if you want to get value of path key of second element in apis array: result.bodyjson.apis.apis1.path

Default assertion

result.statuscode ShouldEqual 200

Documentation

Index

Constants

View Source
const Name = "http"

Name of executor

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new Executor

Types

type Executor

type Executor struct {
	Method            string      `json:"method" yaml:"method"`
	URL               string      `json:"url" yaml:"url"`
	Path              string      `json:"path" yaml:"path"`
	Body              string      `json:"body" yaml:"body"`
	BodyFile          string      `json:"bodyfile" yaml:"bodyfile"`
	MultipartForm     interface{} `json:"multipart_form" yaml:"multipart_form"`
	Headers           Headers     `json:"headers" yaml:"headers"`
	IgnoreVerifySSL   bool        `json:"ignore_verify_ssl" yaml:"ignore_verify_ssl" mapstructure:"ignore_verify_ssl"`
	BasicAuthUser     string      `json:"basic_auth_user" yaml:"basic_auth_user" mapstructure:"basic_auth_user"`
	BasicAuthPassword string      `json:"basic_auth_password" yaml:"basic_auth_password" mapstructure:"basic_auth_password"`
	SkipHeaders       bool        `json:"skip_headers" yaml:"skip_headers" mapstructure:"skip_headers"`
	SkipBody          bool        `json:"skip_body" yaml:"skip_body" mapstructure:"skip_body"`
	Proxy             string      `json:"proxy" yaml:"proxy" mapstructure:"proxy"`
	NoFollowRedirect  bool        `json:"no_follow_redirect" yaml:"no_follow_redirect" mapstructure:"no_follow_redirect"`
	UnixSock          string      `json:"unix_sock" yaml:"unix_sock" mapstructure:"unix_sock"`
}

Executor struct. Json and yaml descriptor are used for json output

func (Executor) GetDefaultAssertions

func (Executor) GetDefaultAssertions() venom.StepAssertions

GetDefaultAssertions return default assertions for this executor Optional

func (Executor) Run

func (Executor) Run(testCaseContext venom.TestCaseContext, l venom.Logger, step venom.TestStep, workdir string) (venom.ExecutorResult, error)

Run execute TestStep

func (Executor) ZeroValueResult added in v0.17.0

func (Executor) ZeroValueResult() venom.ExecutorResult

ZeroValueResult return an empty implemtation of this executor result

type Headers

type Headers map[string]string

Headers represents header HTTP for Request

type Result

type Result struct {
	Executor    Executor    `json:"executor,omitempty" yaml:"executor,omitempty"`
	TimeSeconds float64     `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
	TimeHuman   string      `json:"timehuman,omitempty" yaml:"timehuman,omitempty"`
	StatusCode  int         `json:"statuscode,omitempty" yaml:"statuscode,omitempty"`
	Body        string      `json:"body,omitempty" yaml:"body,omitempty"`
	BodyJSON    interface{} `json:"bodyjson,omitempty" yaml:"bodyjson,omitempty"`
	Headers     Headers     `json:"headers,omitempty" yaml:"headers,omitempty"`
	Err         string      `json:"err,omitempty" yaml:"err,omitempty"`
}

Result represents a step result. Json and yaml descriptor are used for json output

Jump to

Keyboard shortcuts

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