assertions

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldAlmostEqual

func ShouldAlmostEqual(actual interface{}, expected ...interface{}) error

ShouldAlmostEqual makes sure that two parameters are close enough to being equal. The acceptable delta may be specified with a third argument.

func ShouldBeArray added in v1.1.0

func ShouldBeArray(actual interface{}, expected ...interface{}) error

func ShouldBeBetween

func ShouldBeBetween(actual interface{}, expected ...interface{}) error

ShouldBeBetween receives exactly two parameters and ensures that the first is less than the second.

func ShouldBeBetweenOrEqual

func ShouldBeBetweenOrEqual(actual interface{}, expected ...interface{}) error

ShouldBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is between both bounds or equal to one of them.

func ShouldBeBlank

func ShouldBeBlank(actual interface{}, expected ...interface{}) error

ShouldBeBlank receives exactly 1 string parameter and ensures that it is equal to "".

func ShouldBeEmpty

func ShouldBeEmpty(actual interface{}, expected ...interface{}) error

ShouldBeEmpty receives a single parameter (actual) and determines whether or not calling len(actual) would return `0`.

func ShouldBeFalse

func ShouldBeFalse(actual interface{}, expected ...interface{}) error

ShouldBeFalse receives a single parameter and ensures that it is false.

func ShouldBeGreaterThan

func ShouldBeGreaterThan(actual interface{}, expected ...interface{}) error

ShouldBeGreaterThan receives exactly two parameters and ensures that the first is greater than the second.

func ShouldBeGreaterThanOrEqualTo

func ShouldBeGreaterThanOrEqualTo(actual interface{}, expected ...interface{}) error

ShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that the first is greater than or equal to the second.

func ShouldBeIn

func ShouldBeIn(actual interface{}, expected ...interface{}) error

ShouldBeIn receives at least 2 parameters. The first is a proposed member of the collection that is passed in either as the second parameter, or of the collection that is comprised of all the remaining parameters. This assertion ensures that the proposed member is in the collection (using ShouldEqual).

Example of testsuite file:

name: Assertions testsuite
testcases:
  - name: ShouldBeIn
    steps:
    - script: echo 1
      assertions:
      - result.systemoutjson ShouldBeIn 1 2

func ShouldBeLessThan

func ShouldBeLessThan(actual interface{}, expected ...interface{}) error

ShouldBeLessThan receives exactly two parameters and ensures that the first is less than the second.

func ShouldBeLessThanOrEqualTo

func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) error

ShouldBeLessThanOrEqualTo receives exactly two parameters and ensures that the first is less than or equal to the second.

func ShouldBeMap added in v1.1.0

func ShouldBeMap(actual interface{}, expected ...interface{}) error

func ShouldBeNil

func ShouldBeNil(actual interface{}, expected ...interface{}) error

ShouldBeNil receives a single parameter and ensures that it is nil.

func ShouldBeTrue

func ShouldBeTrue(actual interface{}, expected ...interface{}) error

ShouldBeTrue receives a single parameter and ensures that it is true.

func ShouldBeZeroValue

func ShouldBeZeroValue(actual interface{}, expected ...interface{}) error

ShouldBeZeroValue receives a single parameter and ensures that it is the Go equivalent of the default value, or "zero" value.

func ShouldContain

func ShouldContain(actual interface{}, expected ...interface{}) error

ShouldContain receives exactly two parameters. The first is a slice or a single value and the second is a proposed member. Membership is determined using ShouldEqual.

func ShouldContainKey

func ShouldContainKey(actual interface{}, expected ...interface{}) error

ShouldContainKey receives exactly two parameters. The first is a map and the second is a proposed key.

func ShouldContainSubstring

func ShouldContainSubstring(actual interface{}, expected ...interface{}) error

ShouldContainSubstring receives exactly 2 string parameters and ensures that the first contains the second as a substring.

func ShouldEndWith

func ShouldEndWith(actual interface{}, expected ...interface{}) error

ShouldEndWith receives exactly 2 string parameters and ensures that the first ends with the second.

func ShouldEqual

func ShouldEqual(actual interface{}, expected ...interface{}) error

ShouldEqual receives exactly two parameters and does an equality check.

Example of testsuite file:

name: Assertions testsuite
testcases:
- name: test assertion
  steps:
  - script: echo 'foo'
    assertions:
    - result.code ShouldEqual 0

func ShouldEqualTrimSpace

func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) error

ShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the first is equal to the second after removing all leading and trailing whitespace using strings.TrimSpace(first).

func ShouldHappenAfter

func ShouldHappenAfter(actual interface{}, expected ...interface{}) error

ShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the first happens after the second. The arguments have to respect the date format RFC3339 (ie. 2006-01-02T15:04:00+07:00) or humanize format (ie. now, tomorrow, yesterday, 5 minutes ago)

Example of testsuite file:

name: test ShouldHappenAfter
vars:
  time_with_5s_before: 2006-01-02T15:04:00+07:00
  time: 2006-01-02T15:04:05+07:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldHappenAfter "{{.time_with_5s_before}}"
 - name: test assertion with humanize format
   steps:
   - type: exec
     script: "echo {{.venom.datetime}}"
     assertions:
       - "result.systemout ShouldHappenAfter yesterday"
       - "result.systemout ShouldHappenAfter '5 minutes ago'"

func ShouldHappenBefore

func ShouldHappenBefore(actual interface{}, expected ...interface{}) error

ShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the first happens before the second. The arguments have to respect the date format RFC3339 (ie. 2006-01-02T15:04:00+07:00) or humanize format (ie. now, tomorrow, yesterday, 5 minutes ago)

Example of testsuite file:

name: test ShouldHappenBefore
vars:
  time: 2006-01-02T15:04:05+07:00
  time_with_5s_after: 2006-01-02T15:04:10+07:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldHappenBefore "{{.time_with_5s_after}}"
 - name: test assertion with humanize format
   steps:
   - type: exec
     script: "echo {{.venom.datetime}}"
     assertions:
       - "result.systemout ShouldHappenBefore tomorrow"
       - "result.systemout ShouldHappenBefore '5 minutes from now'"

func ShouldHappenBetween

func ShouldHappenBetween(actual interface{}, expected ...interface{}) error

ShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the first happens between (not on) the second and third. The arguments have to respect the date format RFC3339 (ie. 2006-01-02T15:04:00+07:00) or humanize format (ie. yesterday, 5 minutes ago)

Example of testsuite file:

name: test ShouldHappenBetween
vars:
  time_with_5s_before: 2006-01-02T15:04:00+07:00
  time: 2006-01-02T15:04:05+07:00
  time_with_5s_after: 2006-01-02T15:04:10+07:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldHappenBetween "{{.time_with_5s_before}}" "{{.time_with_5s_after}}"
- name: test assertion with humanize format
   steps:
   - type: exec
     script: "echo {{.venom.datetime}}"
     assertions:
       - "result.systemout ShouldHappenBetween yesterday tomorrow"
       - "result.systemout ShouldHappenBetween '5 minutes ago' '5 minutes from now'"

func ShouldHappenOnOrAfter

func ShouldHappenOnOrAfter(actual interface{}, expected ...interface{}) error

ShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that the first happens on or after the second. The arguments have to respect the date format RFC3339 (ie. 2006-01-02T15:04:00+07:00) or humanize format (ie. now, tomorrow, yesterday, 5 minutes ago)

Example of testsuite file:

name: test ShouldHappenOnOrAfter
vars:
  time_with_5s_before: 2006-01-02T15:04:00+07:00
  time: 2006-01-02T15:04:05+07:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldHappenOnOrAfter "{{.time_with_5s_before}}"
 - name: test assertion with humanize format
   steps:
   - type: exec
     script: "echo {{.venom.datetime}}"
     assertions:
       - "result.systemout ShouldHappenOnOrAfter yesterday"
       - "result.systemout ShouldHappenOnOrAfter '5 minutes ago'"

func ShouldHappenOnOrBefore

func ShouldHappenOnOrBefore(actual interface{}, expected ...interface{}) error

ShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that the first happens on or before the second. The arguments have to respect the date format RFC3339 (ie. 2006-01-02T15:04:00+07:00) or humanize format (ie. now, tomorrow, yesterday, 5 minutes ago)

Example of testsuite file:

name: test ShouldHappenOnOrBefore
vars:
  time: 2006-01-02T15:04:05+07:00
  time_with_5s_after: 2006-01-02T15:04:10+07:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldHappenOnOrBefore "{{.time_with_5s_after}}"
 - name: test assertion with humanize format
   steps:
   - type: exec
     script: "echo {{.venom.datetime}}"
     assertions:
       - "result.systemout ShouldHappenOnOrBefore tomorrow"
       - "result.systemout ShouldHappenOnOrBefore '5 minutes from now'"

func ShouldHaveLength

func ShouldHaveLength(actual interface{}, expected ...interface{}) error

ShouldHaveLength receives 2 parameters. The first is a collection to check the length of, the second being the expected length.

func ShouldJSONContain added in v1.2.0

func ShouldJSONContain(actual interface{}, expected ...interface{}) error

ShouldJSONContain receives exactly two parameters. The first is a slice, the second is a proposed JSON member. Equality is determined using ShouldJSONEqual.

func ShouldJSONContainAllWithKey added in v1.2.0

func ShouldJSONContainAllWithKey(actual interface{}, expected ...interface{}) error

ShouldJSONContainAllWithKey receives exactly three parameters. The first is a slice, the second is a key in the inner slice structure and the third is a proposed value associated to the key. Equality is determined using ShouldJSONEqual.

func ShouldJSONContainWithKey added in v1.2.0

func ShouldJSONContainWithKey(actual interface{}, expected ...interface{}) error

ShouldJSONContainWithKey receives exactly three parameters. The first is a slice, the second is a key in the inner slice structure and the third is a proposed value associated to the key. Equality is determined using ShouldJSONEqual.

func ShouldJSONEqual added in v1.2.0

func ShouldJSONEqual(actual interface{}, expected ...interface{}) error

ShouldJSONEqual receives exactly 2 JSON arguments and does a JSON equality check. The latest JSON spec doesn't only allow objects and arrays, but primitive values are valid JSON as well. For object equality keys can be in different order, and whitespace (except in keys or values) is ignored. For arrays the order is important, but whitespace (except in values) is ignored. String, number, true/false are compared as-is. `null` JSON values are currently passed as empty string, and are compared against the "null" string.

For an example scenario see `tests/assertions/ShouldJSONEqual.yml`.

func ShouldMatchRegex added in v1.2.0

func ShouldMatchRegex(actual interface{}, expected ...interface{}) error

ShouldMatchRegex receives exactly two parameters and does a regex match check.

func ShouldNotAlmostEqual

func ShouldNotAlmostEqual(actual interface{}, expected ...interface{}) error

ShouldNotAlmostEqual makes sure that two parameters are not close enough to being equal. The unacceptable delta may be specified with a third argument.

func ShouldNotBeBetween

func ShouldNotBeBetween(actual interface{}, expected ...interface{}) error

ShouldNotBeBetween receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is NOT between both bounds.

func ShouldNotBeBetweenOrEqual

func ShouldNotBeBetweenOrEqual(actual interface{}, expected ...interface{}) error

ShouldNotBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is nopt between the bounds nor equal to either of them.

func ShouldNotBeBlank

func ShouldNotBeBlank(actual interface{}, expected ...interface{}) error

ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is equal to "".

func ShouldNotBeEmpty

func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) error

ShouldNotBeEmpty receives a single parameter (actual) and determines whether or not calling len(actual) would return a value greater than zero.

func ShouldNotBeIn

func ShouldNotBeIn(actual interface{}, expected ...interface{}) error

ShouldNotBeIn receives at least 2 parameters. The first is a proposed member of the collection that is passed in either as the second parameter, or of the collection that is comprised of all the remaining parameters. This assertion ensures that the proposed member is NOT in the collection (using ShouldEqual).

Example of testsuite file:

name: Assertions testsuite
testcases:
  - name: ShouldNotBeIn
    steps:
    - script: echo 3
      assertions:
      - result.systemoutjson ShouldNotBeIn 1 2

func ShouldNotBeNil

func ShouldNotBeNil(actual interface{}, expected ...interface{}) error

ShouldNotBeNil receives a single parameter and ensures that it is not nil.

func ShouldNotContain

func ShouldNotContain(actual interface{}, expected ...interface{}) error

ShouldNotContain receives exactly two parameters. The first is a slice and the second is a proposed member. Membership is determinied using ShouldEqual.

func ShouldNotContainKey

func ShouldNotContainKey(actual interface{}, expected ...interface{}) error

ShouldNotContainKey receives exactly two parameters. The first is a map and the second is a proposed absent key.

func ShouldNotContainSubstring

func ShouldNotContainSubstring(actual interface{}, expected ...interface{}) error

ShouldNotContainSubstring receives exactly 2 string parameters and ensures that the first does NOT contain the second as a substring.

func ShouldNotEndWith

func ShouldNotEndWith(actual interface{}, expected ...interface{}) error

ShouldNotEndWith receives exactly 2 string parameters and ensures that the first does not end with the second.

func ShouldNotEqual

func ShouldNotEqual(actual interface{}, expected ...interface{}) error

ShouldNotEqual receives exactly two parameters and does an inequality check.

func ShouldNotExist

func ShouldNotExist(actual interface{}, expected ...interface{}) error

ShouldNotExist receives a single parameter and ensures that it is nil, blank or zero value

func ShouldNotJSONContain added in v1.2.0

func ShouldNotJSONContain(actual interface{}, expected ...interface{}) error

ShouldNotJSONContain receives exactly two parameters. The first is a slice, the second is a proposed JSON member. Equality is determined using ShouldJSONEqual.

func ShouldNotJSONContainWithKey added in v1.2.0

func ShouldNotJSONContainWithKey(actual interface{}, expected ...interface{}) error

ShouldNotJSONContainWithKey receives exactly three parameters. The first is a slice, the second is a key in the inner slice structure and the third is a proposed value associated to the key. Equality is determined using ShouldJSONEqual.

func ShouldNotStartWith

func ShouldNotStartWith(actual interface{}, expected ...interface{}) error

ShouldNotStartWith receives exactly 2 string parameters and ensures that the first does not start with the second.

func ShouldStartWith

func ShouldStartWith(actual interface{}, expected ...interface{}) error

ShouldStartWith receives exactly 2 string parameters and ensures that the first starts with the second.

func ShouldTimeEqual added in v1.1.0

func ShouldTimeEqual(actual interface{}, expected ...interface{}) error

ShouldTimeEqual receives exactly 2 time.Time arguments and does a time equality check. The arguments have to respect the date format RFC3339, as 2006-01-02T15:04:00+07:00

Example of testsuite file:

name: test ShouldTimeEqual
vars:
  time_expected: 2006-01-02T13:04:00Z
  time: 2006-01-02T15:04:00+02:00
testcases:
- name: test assertion
  steps:
  - type: exec
    script: "echo {{.time}}"
    assertions:
      - result.systemout ShouldTimeEqual "{{.time_expected}}"

Types

type AssertFunc

type AssertFunc func(actual interface{}, expected ...interface{}) error

func Get

func Get(s string) (AssertFunc, bool)

type AssertionError

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

func (*AssertionError) Error

func (e *AssertionError) Error() string

Jump to

Keyboard shortcuts

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