-
Notifications
You must be signed in to change notification settings - Fork 38
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
Mock NTP client #217
Mock NTP client #217
Conversation
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #217 +/- ##
==========================================
+ Coverage 48.05% 52.66% +4.61%
==========================================
Files 19 19
Lines 1130 1143 +13
==========================================
+ Hits 543 602 +59
+ Misses 529 483 -46
Partials 58 58
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
lgtm
Signed-off-by: Meredith Lancaster <[email protected]>
pkg/ntpmonitor/ntpmonitor.go
Outdated
ntpClient NTPClient | ||
} | ||
|
||
func (n *NTPMonitor) WithCustomClient(client NTPClient) { |
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'd propose making a NewFromConfigWithClient
method instead of WithCustomClient
. Otherwise, you're initializing a client twice, once in NewFromConfig
and once in WithCustomClient
.
) | ||
|
||
type MockNTPClient struct { | ||
ignoredServers map[string]string |
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.
What is ignoredServers? Maybe a comment?
Edit: Ah, used for which servers to fail on. Yea, a comment would be helpful!
@@ -160,7 +190,7 @@ func (n *NTPMonitor) QueryNTPServer(srv string) (*ntp.Response, error) { | |||
opts := ntp.QueryOptions{ |
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.
nit: Should QueryNTPServer
be private, because we don't call it elsewhere?
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.
Yeah, looks like it isn't called anywhere else.
} | ||
if !tc.expectTestToPass && err == nil { | ||
t.Errorf("test '%s' unexpectedly passed with a nil error", tc.name) | ||
} |
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.
Can we also test metrics output? (I'm not sure!)
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'll look into this.
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
Signed-off-by: Meredith Lancaster <[email protected]>
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.
Nice, this looks great!
Summary
Closes #148
Adds a mock NTP client so we can add more complete unit testing for the
ntpmonitor
package. The bulk of the logic inNTPMonitor#Start
has been moved intoNTPMonitor#queryServers
so we can test the logic more easily.Release Note
Documentation