SStruct

func SStruct(model interface{}, expectedFields StructFields) TestDeep

SStruct operator (aka strict-Struct) compares the contents of a struct or a pointer on a struct against values of model (if any) and the values of expectedFields. The zero values are compared too even if they are omitted from expectedFields: that is the difference with Struct operator.

model must be the same type as compared data.

expectedFields can be nil, if no TestDeep operators are involved.

To ignore a field, one has to specify it in expectedFields and use the Ignore operator.

td.Cmp(t, td.SStruct(
  Person{
    Name: "John Doe",
  },
  td.StructFields{
    "Age":      td.Between(40, 45),
    "Children": td.Ignore(),
  }),
)

During a match, all expected and zero fields must be found to succeed.

TypeBehind method returns the reflect.Type of model.

See also SStruct godoc.

Example

Base example

CmpSStruct shortcut

func CmpSStruct(t TestingT, got interface{}, model interface{}, expectedFields StructFields, args ...interface{}) bool

CmpSStruct is a shortcut for:

td.Cmp(t, got, td.SStruct(model, expectedFields), args...)

See above for details.

Returns true if the test is OK, false if it fails.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also CmpSStruct godoc.

Example

Base example

T.SStruct shortcut

func (t *T) SStruct(got interface{}, model interface{}, expectedFields StructFields, args ...interface{}) bool

SStruct is a shortcut for:

t.Cmp(got, td.SStruct(model, expectedFields), args...)

See above for details.

Returns true if the test is OK, false if it fails.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also T.SStruct godoc.

Example

Base example