-
Notifications
You must be signed in to change notification settings - Fork 363
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 pkg/apiserver/registry #4304
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4304 +/- ##
==========================================
- Coverage 65.49% 57.98% -7.52%
==========================================
Files 364 388 +24
Lines 52925 55187 +2262
==========================================
- Hits 34665 31998 -2667
- Misses 15704 20764 +5060
+ Partials 2556 2425 -131
|
f112fea
to
b58938f
Compare
watcher, err := r.Watch(context.TODO(), &internalversion.ListOptions{LabelSelector: tt.labelSelector}) | ||
assert.NoError(t, err) | ||
defer watcher.Stop() | ||
for _, expectedObj := range tt.expectedEvents { |
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.
for the "label selector selecting nothing"
test case, I don't think we are actually testing anything? at least it doesn't seem that we are checking that no events are received on the channel.
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.
Thanks for catching it. I have added a check for unexpected events.
name: "one object", | ||
object: stats, | ||
expectedTable: &metav1.Table{ | ||
ColumnDefinitions: []metav1.TableColumnDefinition{ |
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.
is it useful to redefine ColumnDefinitions
here, or could we just use a shared global variable with the ConvertToTable
function?
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.
extracted a variable as you suggested
d68b723
to
3e6d26b
Compare
3e6d26b
to
800cc2b
Compare
Signed-off-by: Quan Tian <qtian@vmware.com>
800cc2b
to
2313a71
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.
LGTM
case <-time.NewTimer(time.Second).C: | ||
t.Errorf("Failed to get expected object %v from watcher in time", expectedObj) |
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 think the timer won't be garbage collected until it fires, but that's probably not an issue for unit tests...
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.
You are right. Since this is not the first place not stopping the timer explicitly in unit tests, I will leave it as is for now.
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
/skip-all |
Signed-off-by: Quan Tian <qtian@vmware.com>
Signed-off-by: Quan Tian <qtian@vmware.com>
Signed-off-by: Quan Tian qtian@vmware.com
For #4142