-
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/ipfix #4415
Conversation
Codecov Report
@@ 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
|
pkg/ipfix/ipfix_collector_test.go
Outdated
tcpTransport = "tcp" | ||
udpTransport = "udp" | ||
hostPortIPv4 = "127.0.0.1:0" | ||
hostPortIPv6 = "[::1]:0" |
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.
same as above HostIPv6Port
pkg/ipfix/ipfix_collector_test.go
Outdated
const ( | ||
tcpTransport = "tcp" | ||
udpTransport = "udp" | ||
hostPortIPv4 = "127.0.0.1:0" |
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.
use name like hostIPv4Port
pkg/ipfix/ipfix_collector_test.go
Outdated
) | ||
|
||
const ( | ||
tcpTransport = "tcp" |
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.
name like protocol type will make more sense
pkg/ipfix/ipfix_collector_test.go
Outdated
assert.Equal(t, tt.expectedNum, cp.GetNumConnToCollector()) | ||
} else { | ||
assert.Equal(t, tt.err, err.Error()) | ||
} |
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.
Coverage for GetNumRecordsReceived ?
pkg/ipfix/ipfix_intermediate_test.go
Outdated
}) | ||
} | ||
} | ||
|
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.
few functions like SetCorrelatedFieldsFilled in ipfix_intermediate.go , yet to be covered !
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.
Increase the coverage percentage
coverage has been increased and other comments have been addressed @rajnkamr |
pkg/ipfix/ipfix_collector_test.go
Outdated
@@ -0,0 +1,22 @@ | |||
package ipfix |
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.
Add license warranty for every new file like other files.
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.
fixed
pkg/ipfix/ipfix_process_test.go
Outdated
@@ -0,0 +1,101 @@ | |||
// Copyright 2020 Antrea Authors |
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.
// Copyright 2020 Antrea Authors | |
// Copyright 2022 Antrea Authors |
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.
fixed for all files
pkg/ipfix/ipfix_process_test.go
Outdated
input: exporter.ExporterInput{ | ||
CollectorAddress: "tcp", | ||
}, | ||
expectedError: "error while initializing IPFIX exporting process: dial: unknown network ", |
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.
expectedError: "error while initializing IPFIX exporting process: dial: unknown network ", | |
expectedError: "error while initializing IPFIX exporting process: dial: unknown network", |
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.
fixed
pkg/ipfix/ipfix_process_test.go
Outdated
"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" |
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.
This alias is unnecessary since it is the same as the suffix of the lib.
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.
fixed
35bc252
to
6b2b7a6
Compare
c9a18c9
to
50e83bf
Compare
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= |
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.
Are they added automatically? Not sure why there were missing on main branch and suddenly added 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.
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?
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.
Now the test is failing, I think they shouldn't be added.
https://github.com/antrea-io/antrea/actions/runs/3877253764/jobs/6612065974
pkg/ipfix/ipfix_collector_test.go
Outdated
defer cp.Stop() | ||
assert.NotNil(t, cp.GetMsgChan()) | ||
assert.Equal(t, 0, int(cp.GetNumRecordsReceived())) | ||
assert.Equal(t, 0, int(cp.GetNumConnToCollector())) |
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.
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.
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.
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= |
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.
Now the test is failing, I think they shouldn't be added.
https://github.com/antrea-io/antrea/actions/runs/3877253764/jobs/6612065974
pkg/ipfix/ipfix_registry_test.go
Outdated
reg.LoadRegistry() | ||
element, err := reg.GetInfoElement(tt.name, tt.enterpriseID) | ||
if tt.expectedError == "" { | ||
assert.Equal(t, tt.expectedElementID, element.ElementId) |
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.
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.
pkg/ipfix/ipfix_registry_test.go
Outdated
if tt.expectedError == "" { | ||
assert.Equal(t, tt.expectedElementID, element.ElementId) | ||
} else { | ||
assert.Equal(t, tt.expectedError, err.Error()) |
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.
ditto, err.Error()
could panic when got error is nil, it could use assert.ErrorContains
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
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: Naman Agarwal <naman.agarwal75@gmail.com>
For #4142
Signed-off-by: Naman Agarwal naman.agarwal75@gmail.com