-
Notifications
You must be signed in to change notification settings - Fork 116
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
Enhance defaultHWAddrFunc() and tests to hit 100% coverage #57
Conversation
Codecov Report
@@ Coverage Diff @@
## master #57 +/- ##
========================================
+ Coverage 98.92% 100% +1.07%
========================================
Files 4 4
Lines 279 279
========================================
+ Hits 276 279 +3
+ Misses 2 0 -2
+ Partials 1 0 -1
Continue to review full report at Codecov.
|
a78bf44
to
75abe58
Compare
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.
Looks nice. This review contains a few nitpicks, mostly on matters of style.
generator_test.go
Outdated
@@ -376,6 +378,103 @@ func testNewV5DifferentNamespaces(t *testing.T) { | |||
} | |||
} | |||
|
|||
func Test_defaultHWAddrFunc(t *testing.T) { |
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.
I don't like this underscore very much, because no other top level tests have one. Indeed, TestdefaultHWAttrFunc
does not look nice, but I wouldn't mind TestDefaultHWAddrFunc
, even though the token after Test
does not match the function being tested exactly.
I don't feel strongly about this at all, so we can leave it as-is if you'd like.
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.
Agree with @acln0 , Let's have TestDefaultHWAddrFunc
@@ -284,9 +284,11 @@ func newFromHash(h hash.Hash, ns UUID, name string) UUID { | |||
return u | |||
} | |||
|
|||
var netInterfaces = net.Interfaces |
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.
At the call site for netInterfaces
, we use ifaces, err := netInterfaces()
and rely on type inference. I would prefer adding an explicit type here, in the style of these hooks: https://golang.org/pkg/internal/poll/#pkg-variables, to better communicate the signature of what is being hooked, so the reader doesn't have to go through yet another indirection.
Perhaps var netInterfaces func() ([]net.Interface, error) = net.Interfaces
.
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.
I don't really like how it clutters up the code. It would be easier for my editor to give me the function header definition over trying to read that line.
I was trying to hit 100% without making the code too messy.
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.
I want to push back a little here. I like having the type inline, be it a little bit more cluttered as it may. Editors might help alleviate the extra indirection via highlighting, but I'd like to avoid it altogether.
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.
Finally getting back around to working on this PR, and this change results in a golint
failure.
generator.go:287:19: should omit type func() ([]net.Interface, error) from declaration of var netInterfaces; it will be inferred from the right-hand side (golint)
var netInterfaces func() ([]net.Interface, error) = net.Interfaces
^
As a result I'm just going to omit it at this time.
Outside of @acln0's comments this looks good |
Sorry for the delay, October was busy for me. Let me do some homework on this one. |
This updates `defaultHWAddrFunc` to use a package-level variable for calling `net.Interfaces()`, so that we can mock it in unit tests. Doing so, and writing the related test, allows us to hit 100% coverage. Signed-off-by: Tim Heckman <[email protected]>
75abe58
to
8b46831
Compare
Changes were made since then; and some of the requested changes are flagged by golint
generator_test.go
Outdated
@@ -376,6 +378,103 @@ func testNewV5DifferentNamespaces(t *testing.T) { | |||
} | |||
} | |||
|
|||
func Test_defaultHWAddrFunc(t *testing.T) { |
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.
func Test_defaultHWAddrFunc(t *testing.T) { | |
func TestDefaultHWAddrFunc(t *testing.T) { |
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.
Left a code suggestion for the one finding that I think has been blocking the PR 😆
Codecov Report
@@ Coverage Diff @@
## master #57 +/- ##
===========================================
+ Coverage 99.02% 100.00% +0.97%
===========================================
Files 4 4
Lines 411 411
===========================================
+ Hits 407 411 +4
+ Misses 3 0 -3
+ Partials 1 0 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This updates
defaultHWAddrFunc
to use a package-level variable for callingnet.Interfaces()
, so that we can mock it in unit tests.Doing so, and writing the related test, allows us to hit 100% coverage.
Signed-off-by: Tim Heckman [email protected]