Skip to content

Assertion for determining if a maps values exist within another map? #762

@Mo0rBy

Description

@Mo0rBy

I'd like to assert that mapA contains all the key:value pairs in mapB but mapA can contain more key:value pairs.

For examples:

mapA := map[string]string{
	"keyA": "valA",
	"key2": "val2",
	"keyB": "valB",
	"key1": "val1",
}

mapB := map[string]string{
	"key1": "val1",
	"key2": "val2",
}

Expect(mapA).To(Contain(mapB))

Very similar behaviour to the ContainElements() matcher, but for maps instead of slices and without needing to explicitly define the keys or values that you are expecting, it should be able to infer that from mapA.

I think there is probably a way to do this with the existing matchers somehow, but I can't figure it out if there is, for example

I think this could be a common enough use case that it should have its own matcher as well, so I thought I should post my query here.

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