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

Enhance defaultHWAddrFunc() and tests to hit 100% coverage #57

Merged
merged 3 commits into from Sep 9, 2022

Conversation

theckman
Copy link
Member

@theckman theckman commented Oct 6, 2018

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 t@heckman.io

@codecov-io
Copy link

codecov-io commented Oct 6, 2018

Codecov Report

Merging #57 into master will increase coverage by 1.07%.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
generator.go 100% <100%> (+2.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b08a5c...8b46831. Read the comment docs.

acln0
acln0 previously requested changes Oct 6, 2018
Copy link
Member

@acln0 acln0 left a 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 Show resolved Hide resolved
generator_test.go Show resolved Hide resolved
@@ -376,6 +378,103 @@ func testNewV5DifferentNamespaces(t *testing.T) {
}
}

func Test_defaultHWAddrFunc(t *testing.T) {
Copy link
Member

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.

Copy link
Contributor

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

generator_test.go Outdated Show resolved Hide resolved
@@ -284,9 +284,11 @@ func newFromHash(h hash.Hash, ns UUID, name string) UUID {
return u
}

var netInterfaces = net.Interfaces
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@theckman theckman Jan 11, 2019

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.

@adamdecaf
Copy link
Member

Outside of @acln0's comments this looks good

@theckman
Copy link
Member Author

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 <t@heckman.io>
@theckman theckman dismissed acln0’s stale review January 11, 2019 15:18

Changes were made since then; and some of the requested changes are flagged by golint

@@ -376,6 +378,103 @@ func testNewV5DifferentNamespaces(t *testing.T) {
}
}

func Test_defaultHWAddrFunc(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func Test_defaultHWAddrFunc(t *testing.T) {
func TestDefaultHWAddrFunc(t *testing.T) {

Copy link
Contributor

@cameracker cameracker left a 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-commenter
Copy link

Codecov Report

Merging #57 (20095e6) into master (f267b3d) will increase coverage by 0.97%.
The diff coverage is 100.00%.

@@             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     
Impacted Files Coverage Δ
generator.go 100.00% <100.00%> (+2.51%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cameracker cameracker merged commit e420387 into master Sep 9, 2022
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.

None yet

8 participants