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

Add unit test for Get in pkg/labels/labels.go #7116

Merged
merged 1 commit into from
May 12, 2020
Merged

Add unit test for Get in pkg/labels/labels.go #7116

merged 1 commit into from
May 12, 2020

Conversation

hs0210
Copy link
Contributor

@hs0210 hs0210 commented Apr 11, 2020

This PR is about adding a unit test for Get in pkg/labels/labels.go.

Signed-off-by: Hu Shuai hus.fnst@cn.fujitsu.com

@cstyan
Copy link
Member

cstyan commented Apr 14, 2020

LGTM but given that this is the 2nd PR for tests in this package recently it seems likely there might be a few more that could be added. If you find any please add them to this PR @hs0210 :)

@hs0210
Copy link
Contributor Author

hs0210 commented Apr 15, 2020

PTAL

@hs0210
Copy link
Contributor Author

hs0210 commented Apr 28, 2020

@cstyan I have added two other tests. PTAL. If there are still problems, I will fix it.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those tests are quite simple... that's why maybe there is a room for adding more tests in this PR for other methofs in the labels package, but I think I am happy to merge this as long as comments are addressed.

Generally, please try to make sure the code is concise. 🤗 Having extra variable or unnecessary table test cost in terms of complexity and readability (you need to traverse more lines and the user expects more things happening). You can read more here

@@ -485,3 +485,82 @@ func TestLabels_Has(t *testing.T) {
testutil.Equals(t, test.expected, got, "unexpected comparison result for test case %d", i)
}
}

func TestLabels_Get(t *testing.T) {
tests := []struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This table test for single line test might be an overkill..

The same test will have just 2 lines...

Can we add just two lines instead?

}

func TestLabels_Copy(t *testing.T) {
expected := Labels{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, but one line

expected["aaa"] = "111"
expected["bbb"] = "222"

labelsSet := Labels{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for any of those variables... just one line is enough.

testutil.Equals(t, map[string]string{"aaa":"111","bbb":"222"}, Labels{
{
			Name:  "aaa",
			Value: "111",
		},
		{
			Name:  "bbb",
			Value: "222",
		},
	}.Map())

This PR is about adding some unit tests for funcs in pkg/labels/labels.go.

Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
@hs0210
Copy link
Contributor Author

hs0210 commented May 8, 2020

@bwplotka PTAL.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool 👍

LGTM, thanks.

@bwplotka bwplotka merged commit da217cb into prometheus:master May 12, 2020
kakkoyun pushed a commit to kakkoyun/prometheus that referenced this pull request Jun 8, 2020
This PR is about adding some unit tests for funcs in pkg/labels/labels.go.

Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
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

Successfully merging this pull request may close these issues.

3 participants