📖 9 min read (~ 1800 words).

Equality

Asserting Two Things Are Equal

Assertions

GoDoc

All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2

This domain exposes 12 functionalities.

Empty

Empty asserts that the given value is “empty”.

Zero values are “empty”.

Arrays are “empty” if every element is the zero value of the type (stricter than “empty”).

Slices, maps and channels with zero length are “empty”.

Pointer values are “empty” if the pointer is nil or if the pointed value is “empty”.

Examples
	assertions.Empty(t, obj)
	success: ""
	failure: "not empty"

Equal

Equal asserts that two objects are equal.

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).

Function equality cannot be determined and will always fail.

Examples
	assertions.Equal(t, 123, 123)
	success: 123, 123
	failure: 123, 456

EqualExportedValues

EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ.

Examples
	 type S struct {
		Exported     	int
		notExported   	int
	 }
	assertions.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
	assertions.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
	success: &dummyStruct{A: "a", b: 1}, &dummyStruct{A: "a", b: 2}
	failure:  &dummyStruct{A: "a", b: 1}, &dummyStruct{A: "b", b: 1}

EqualValues

EqualValues asserts that two objects are equal or convertible to the larger type and equal.

Examples
	assertions.EqualValues(t, uint32(123), int32(123))
	success: uint32(123), int32(123)
	failure: uint32(123), int32(456)

Exactly

Exactly asserts that two objects are equal in value and type.

Examples
	assertions.Exactly(t, int32(123), int64(123))
	success: int32(123), int32(123)
	failure: int32(123), int64(123)

Nil

Nil asserts that the specified object is nil.

Examples
	assertions.Nil(t, err)
	success: nil
	failure: "not nil"

NotEmpty

NotEmpty asserts that the specified object is NOT [Empty].

Examples
	if assert.NotEmpty(t, obj) {
		assertions.Equal(t, "two", obj[1])
	}
	success: "not empty"
	failure: ""

NotEqual

NotEqual asserts that the specified values are NOT equal.

Examples
	assertions.NotEqual(t, obj1, obj2)
Pointer variable equality is determined based on the equality of the
referenced values (as opposed to the memory addresses).
	success: 123, 456
	failure: 123, 123

NotEqualValues

NotEqualValues asserts that two objects are not equal even when converted to the same type.

Examples
	assertions.NotEqualValues(t, obj1, obj2)
	success: uint32(123), int32(456)
	failure: uint32(123), int32(123)

NotNil

NotNil asserts that the specified object is not nil.

Examples
assertions.NotNil(t, err)
	success: "not nil"
	failure: nil

NotSame

NotSame asserts that two pointers do not reference the same object.

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

Examples
	assertions.NotSame(t, ptr1, ptr2)
	success: &staticVar, ptr("static string")
	failure: &staticVar, staticVarPtr

Same

Same asserts that two pointers reference the same object.

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

Examples
	assertions.Same(t, ptr1, ptr2)
	success: &staticVar, staticVarPtr
	failure: &staticVar, ptr("static string")


Generated with github.com/go-openapi/testify/v2/codegen