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/ipfix #4415

Merged
merged 1 commit into from
Jan 16, 2023
Merged

Add unit test for pkg/ipfix #4415

merged 1 commit into from
Jan 16, 2023

Conversation

NamanAg30
Copy link
Contributor

For #4142
Signed-off-by: Naman Agarwal naman.agarwal75@gmail.com

@codecov
Copy link

codecov bot commented Nov 25, 2022

Codecov Report

Merging #4415 (0da7785) into main (a9fd9d2) will decrease coverage by 1.59%.
The diff coverage is n/a.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4415      +/-   ##
==========================================
- Coverage   65.51%   63.92%   -1.60%     
==========================================
  Files         402      402              
  Lines       57238    57238              
==========================================
- Hits        37502    36590     -912     
- Misses      17013    17945     +932     
+ Partials     2723     2703      -20     
Flag Coverage Δ
integration-tests 34.78% <0.00%> (+0.05%) ⬆️
kind-e2e-tests 40.96% <0.00%> (-5.42%) ⬇️
unit-tests 50.27% <0.00%> (-0.77%) ⬇️
Impacted Files Coverage Δ
pkg/agent/proxy/endpointslicecache.go 0.00% <0.00%> (-83.60%) ⬇️
...gent/nodeportlocal/portcache/port_table_windows.go 0.00% <0.00%> (-64.43%) ⬇️
...g/agent/controller/serviceexternalip/controller.go 35.83% <0.00%> (-32.77%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam.go 52.81% <0.00%> (-22.95%) ⬇️
pkg/agent/proxy/proxier.go 57.25% <0.00%> (-18.83%) ⬇️
pkg/agent/ipassigner/responder/arp_responder.go 55.29% <0.00%> (-17.65%) ⬇️
...pportbundlecollection/support_bundle_controller.go 47.98% <0.00%> (-17.59%) ⬇️
pkg/agent/cniserver/ipam/ipam_delegator.go 54.54% <0.00%> (-13.64%) ⬇️
pkg/agent/controller/trafficcontrol/controller.go 70.83% <0.00%> (-11.95%) ⬇️
pkg/util/k8s/client.go 35.00% <0.00%> (-11.67%) ⬇️
... and 43 more

tcpTransport = "tcp"
udpTransport = "udp"
hostPortIPv4 = "127.0.0.1:0"
hostPortIPv6 = "[::1]:0"
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above HostIPv6Port

const (
tcpTransport = "tcp"
udpTransport = "udp"
hostPortIPv4 = "127.0.0.1:0"
Copy link
Contributor

Choose a reason for hiding this comment

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

use name like hostIPv4Port

)

const (
tcpTransport = "tcp"
Copy link
Contributor

Choose a reason for hiding this comment

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

name like protocol type will make more sense

assert.Equal(t, tt.expectedNum, cp.GetNumConnToCollector())
} else {
assert.Equal(t, tt.err, err.Error())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverage for GetNumRecordsReceived ?

})
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

few functions like SetCorrelatedFieldsFilled in ipfix_intermediate.go , yet to be covered !

Copy link
Contributor

@rajnkamr rajnkamr left a comment

Choose a reason for hiding this comment

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

Increase the coverage percentage

@NamanAg30
Copy link
Contributor Author

coverage has been increased and other comments have been addressed @rajnkamr

@@ -0,0 +1,22 @@
package ipfix
Copy link
Contributor

Choose a reason for hiding this comment

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

Add license warranty for every new file like other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,101 @@
// Copyright 2020 Antrea Authors
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
// Copyright 2020 Antrea Authors
// Copyright 2022 Antrea Authors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed for all files

input: exporter.ExporterInput{
CollectorAddress: "tcp",
},
expectedError: "error while initializing IPFIX exporting process: dial: unknown network ",
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
expectedError: "error while initializing IPFIX exporting process: dial: unknown network ",
expectedError: "error while initializing IPFIX exporting process: dial: unknown network",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

"github.com/stretchr/testify/assert"
"github.com/vmware/go-ipfix/pkg/entities"
"github.com/vmware/go-ipfix/pkg/exporter"
test "github.com/vmware/go-ipfix/pkg/test"
Copy link
Contributor

Choose a reason for hiding this comment

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

This alias is unnecessary since it is the same as the suffix of the lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

go.sum Outdated
@@ -100,6 +100,7 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/sarama v1.27.2 h1:1EyY1dsxNDUQEv0O/4TsjosHI2CgB1uo9H/v56xzTxc=
Copy link
Member

Choose a reason for hiding this comment

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

Are they added automatically? Not sure why there were missing on main branch and suddenly added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was failing on github 'Go / Check tidy, code generation and manifest (pull_request)'...so on running go mod tidy these lines were added....Should I remove them?

Copy link
Member

Choose a reason for hiding this comment

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

Now the test is failing, I think they shouldn't be added.
https://github.com/antrea-io/antrea/actions/runs/3877253764/jobs/6612065974

defer cp.Stop()
assert.NotNil(t, cp.GetMsgChan())
assert.Equal(t, 0, int(cp.GetNumRecordsReceived()))
assert.Equal(t, 0, int(cp.GetNumConnToCollector()))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, not related to your test code, but actually the whole CollectorInput struct itself is meaningless as it just acts as a proxy class, which is not even needed in Go.
I have created #4505 to completely remove the unneeded structs. Thus, only test code in ipfix_registry_test.go is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So should I remove ipfix_collector_test.go , ipfix_intermediate_test.go and ipfix_process_test.go from the PR or will this PR be merged only after #4505 ?

go.sum Outdated
@@ -100,6 +100,7 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/sarama v1.27.2 h1:1EyY1dsxNDUQEv0O/4TsjosHI2CgB1uo9H/v56xzTxc=
Copy link
Member

Choose a reason for hiding this comment

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

Now the test is failing, I think they shouldn't be added.
https://github.com/antrea-io/antrea/actions/runs/3877253764/jobs/6612065974

reg.LoadRegistry()
element, err := reg.GetInfoElement(tt.name, tt.enterpriseID)
if tt.expectedError == "" {
assert.Equal(t, tt.expectedElementID, element.ElementId)
Copy link
Member

Choose a reason for hiding this comment

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

It should use require.NoError to ensure no error is returned first, otherwise accessing element.ElementId directly may panic if code doesn't work as expected.

if tt.expectedError == "" {
assert.Equal(t, tt.expectedElementID, element.ElementId)
} else {
assert.Equal(t, tt.expectedError, err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

ditto, err.Error() could panic when got error is nil, it could use assert.ErrorContains

Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
Copy link
Member

@tnqn tnqn 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

tnqn commented Jan 16, 2023

/skip-all

@tnqn tnqn merged commit 8961420 into antrea-io:main Jan 16, 2023
GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Jan 27, 2023
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.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.

4 participants