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

Add unit test for pkg/apiserver/registry #4304

Merged
merged 1 commit into from
Oct 19, 2022

Conversation

tnqn
Copy link
Member

@tnqn tnqn commented Oct 17, 2022

Signed-off-by: Quan Tian qtian@vmware.com

For #4142

@tnqn tnqn mentioned this pull request Oct 17, 2022
37 tasks
@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #4304 (0a7fd95) into main (5e96c8c) will decrease coverage by 7.51%.
The diff coverage is n/a.

❗ Current head 0a7fd95 differs from pull request most recent head d68b723. Consider uploading reports for the commit d68b723 to get more accurate results

Impacted file tree graph

@@            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     
Flag Coverage Δ
integration-tests 34.42% <0.00%> (+0.02%) ⬆️
kind-e2e-tests 29.44% <0.00%> (-19.17%) ⬇️
unit-tests 45.50% <0.00%> (-1.21%) ⬇️
Impacted Files Coverage Δ
pkg/agent/proxy/endpointslicecache.go 0.00% <0.00%> (-83.60%) ⬇️
...g/agent/apiserver/handlers/featuregates/handler.go 4.54% <0.00%> (-77.28%) ⬇️
...agent/controller/traceflow/traceflow_controller.go 14.03% <0.00%> (-58.93%) ⬇️
...kg/apiserver/registry/system/supportbundle/rest.go 14.34% <0.00%> (-58.27%) ⬇️
pkg/agent/nodeportlocal/npl_agent_init.go 0.00% <0.00%> (-57.15%) ⬇️
pkg/agent/nodeportlocal/rules/iptable_rule.go 0.00% <0.00%> (-55.79%) ⬇️
pkg/agent/controller/traceflow/packetin.go 12.81% <0.00%> (-50.63%) ⬇️
pkg/support/dump.go 7.90% <0.00%> (-49.16%) ⬇️
...nt/apiserver/handlers/serviceexternalip/handler.go 3.70% <0.00%> (-48.15%) ⬇️
.../agent/apiserver/handlers/networkpolicy/handler.go 2.04% <0.00%> (-46.94%) ⬇️
... and 121 more

@tnqn tnqn force-pushed the unit-test-for-registry branch 2 times, most recently from f112fea to b58938f Compare October 17, 2022 16:56
antoninbas
antoninbas previously approved these changes Oct 17, 2022
watcher, err := r.Watch(context.TODO(), &internalversion.ListOptions{LabelSelector: tt.labelSelector})
assert.NoError(t, err)
defer watcher.Stop()
for _, expectedObj := range tt.expectedEvents {
Copy link
Contributor

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.

Copy link
Member Author

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{
Copy link
Contributor

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?

Copy link
Member Author

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

Signed-off-by: Quan Tian <qtian@vmware.com>
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +191 to +192
case <-time.NewTimer(time.Second).C:
t.Errorf("Failed to get expected object %v from watcher in time", expectedObj)
Copy link
Contributor

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...

Copy link
Member Author

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.

Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM

@tnqn
Copy link
Member Author

tnqn commented Oct 19, 2022

/skip-all

@tnqn tnqn merged commit 8982e08 into antrea-io:main Oct 19, 2022
@tnqn tnqn deleted the unit-test-for-registry branch October 19, 2022 03:15
@vicky-liu vicky-liu added this to the Antrea v1.9 release milestone Oct 20, 2022
hongliangl pushed a commit to hongliangl/antrea that referenced this pull request Oct 22, 2022
Signed-off-by: Quan Tian <qtian@vmware.com>
heanlan pushed a commit to heanlan/antrea that referenced this pull request Mar 29, 2023
Signed-off-by: Quan Tian <qtian@vmware.com>
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.

5 participants