Skip to content

Slice comparison matchers like HaveExactElements with a custom matcher #724

@michaelbeaumont

Description

@michaelbeaumont

Probably I'm missing something obvious from the docs but say I have two slices of structs that I want to compare but only on one field.

I want to write something like:

Expect(actual).To(HaveExactElements(
    expected, 
    gstruct.MatchFields(gstruct.IgnoreExtra, Fields{"FieldName": Equal}),
))

But the values in Fields have to be already instantiated matchers. But what do I call Equal(??) with?

or something like

Expect(actual).To(HaveExactElements(expected, EqualOnFields("FieldName")))

I can see that HaveExactElements dynamically creates its default Equal() matcher from the expected elements but it wants a given custom matcher to already exist.

This is ultimately so painful because it's so painful to map values in go but it feels like this is something Gomega is in a good position to solve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions