Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: assert.MapSubset (or just support maps in assert.Subset) #1173

Open
SleepyBrett opened this issue Apr 1, 2022 · 8 comments
Open

Comments

@SleepyBrett
Copy link

SleepyBrett commented Apr 1, 2022

or perhaps expand subset so it can also handle maps.

given

a := map[string]string{
		"one": "foo",
		"two": "bar",
		"three": "baz",
	 }

b := map[string]string{
		"one": "foo",
		"three": "baz",
	 }

c := map[string]string{
		"one": "foo",
		"three": "notbaz",
	 }


assert.MapSubset(t, a, b, "a does not contain b") // will pass
assert.MapSubset(t, b, a, "b does not contain a") // will fail b does not have two=bar
assert.MapSubset(t, a, c, "a does not contain c") // will fail a does not have three=notbaz
@SleepyBrett SleepyBrett changed the title Would love a MapSubset proposal: assert.MapSubset (or just support maps in assert.Subset) Apr 1, 2022
@brackendawson
Copy link
Collaborator

Enhancing Subset would definitely be better IMO.

One question, should this assert true?

a := map[string]string{
		"one": "foo",
		"two": "bar",
	 }

b := map[string]string{
		"one": "baz",
	 }

assert.Subset(t, a, b)

Does it test that the key and value are in the superset, or does it follow two value dereference (_, ok := a["one"]) which only checks the key? It would need to be documented.

@SleepyBrett
Copy link
Author

it should test both the key and the value.

@OladapoAjala
Copy link
Contributor

@brackendawson What is the process to having this proposal accepted? If accepted @SleepyBrett can I work on it?

@brackendawson
Copy link
Collaborator

That would be open a pull request and then hope a maintainer returns.

@OladapoAjala
Copy link
Contributor

@brackendawson sure thanks, would create a PR.

@OladapoAjala
Copy link
Contributor

Hello @brackendawson @SleepyBrett I created a PR for this issue here: #1178

@tisonkun
Copy link

FYI testify Contains on Map type validates by map keys, not entries.

@eikenb
Copy link

eikenb commented Feb 9, 2023

While looking for this exact functionality I came across this ticket and #704 which looks like a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants