top

Package httpexpect helps to write nice tests for your HTTP API.

Usage example

See example directory:

- https://godoc.org/github.com/gavv/httpexpect/example
- https://github.com/gavv/httpexpect/tree/master/example

Value equality

Whenever values are checked for equality in httpexpect, they are converted to "canonical form":

- type aliases are removed
- numeric types are converted to float64
- non-nil interfaces pointing to nil slices and maps are replaced with nil interfaces
- structs are converted to map[string]interface{}

This is equivalent to subsequently json.Marshal() and json.Unmarshal() the value.

Failure handling

When some check fails, failure is reported. If non-fatal failures are used (see Reporter interface), execution is continued and instance that was checked is marked as failed.

If specific instance is marked as failed, all subsequent checks are ignored for this instance and for any child instances retrieved after failure.

Example:

array := NewArray(NewAssertReporter(t), []interface{}{"foo", 123})

e0 := array.Element(0)  // success
e1 := array.Element(1)  // success

s0 := e0.String()       // success
s1 := e1.String()       // failure; e1 and s1 are marked as failed, e0 and s0 are not

s0.Equal("foo")         // success
s1.Equal("bar")         // this check is ignored because s1 is marked as failed

Imports 4 package(s) ΒΆ

  1. github.com/gavv/gojsondiff
  2. github.com/stretchr/testify/assert
  3. github.com/gavv/gojsondiff/formatter
  4. github.com/stretchr/testify/require