-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
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 :) |
PTAL |
@cstyan I have added two other tests. PTAL. If there are still problems, I will fix it. |
There was a problem hiding this 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
pkg/labels/labels_test.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
pkg/labels/labels_test.go
Outdated
} | ||
|
||
func TestLabels_Copy(t *testing.T) { | ||
expected := Labels{ |
There was a problem hiding this comment.
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
pkg/labels/labels_test.go
Outdated
expected["aaa"] = "111" | ||
expected["bbb"] = "222" | ||
|
||
labelsSet := Labels{ |
There was a problem hiding this comment.
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>
@bwplotka PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 👍
LGTM, thanks.
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>
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