Skip to content

Commit 6385c40

Browse files
authored
fix(tests): Fix packetparser tests (#1977)
# Description This PR fixes unit test failures in the `packetparser` plugin: - Mocks `metrics.ParsedPacketsCounter` in `TestReadDataPodLevelEnabled` to prevent a nil pointer dereference during test execution. - Updates the expected dynamic header content in `TestPacketParseGenerate` to match the actual generated output, which now includes `DATA_SAMPLING_RATE` and `BYPASS_LOOKUP_IP_OF_INTEREST` definitions. ## Related PRs This test was broken in the following PRs - #624 - #1767 ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/Contributing/overview). - [x] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [x] I have correctly attributed the author(s) of the code. - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [x] I have updated the documentation, if necessary. - [x] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed <img width="1624" height="1343" alt="image" src="https://github.com/user-attachments/assets/9549ed15-7c62-4537-a806-2d2368d3fc66" /> ## Additional Notes We have a bigger issue which is CI is not showing a failure when single test fails, we will look into that and create another PR to fix that. See this example (FAIL not caught) - reference #1688 https://github.com/microsoft/retina/actions/runs/20115412850/job/57723528708#step:4:3145 --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
1 parent 6447b7e commit 6385c40

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/plugin/packetparser/packetparser_linux_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ func TestReadDataPodLevelEnabled(t *testing.T) {
344344

345345
metrics.LostEventsCounter = mICounterVec
346346

347+
mParsedPacketsCounter := metrics.NewMockCounterVec(ctrl)
348+
mParsedPacketsCounter.EXPECT().WithLabelValues(gomock.Any()).Return(prometheus.NewCounter(prometheus.CounterOpts{})).AnyTimes()
349+
metrics.ParsedPacketsCounter = mParsedPacketsCounter
350+
347351
exCh := make(chan *v1.Event, 10)
348352
p.SetupChannel(exCh)
349353

@@ -560,22 +564,22 @@ func TestPacketParseGenerate(t *testing.T) {
560564
{
561565
name: "PodLevelEnabled",
562566
cfg: cfgPodLevelEnabled,
563-
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 1\n#define DATA_AGGREGATION_LEVEL 0\n",
567+
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 1\n#define DATA_AGGREGATION_LEVEL 0\n#define DATA_SAMPLING_RATE 0\n",
564568
},
565569
{
566570
name: "ConntrackMetricsEnabled",
567571
cfg: cfgConntrackMetricsEnabled,
568-
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 1\n#define ENABLE_CONNTRACK_METRICS 1\n#define DATA_AGGREGATION_LEVEL 1\n",
572+
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 1\n#define ENABLE_CONNTRACK_METRICS 1\n#define DATA_AGGREGATION_LEVEL 1\n#define DATA_SAMPLING_RATE 0\n",
569573
},
570574
{
571575
name: "DataAggregationLevelLow",
572576
cfg: cfgDataAggregationLevelLow,
573-
expectedContents: "#define DATA_AGGREGATION_LEVEL 0\n",
577+
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 0\n#define DATA_AGGREGATION_LEVEL 0\n#define DATA_SAMPLING_RATE 0\n",
574578
},
575579
{
576580
name: "DataAggregationLevelHigh",
577581
cfg: cfgDataAggregationLevelHigh,
578-
expectedContents: "#define DATA_AGGREGATION_LEVEL 1\n",
582+
expectedContents: "#define BYPASS_LOOKUP_IP_OF_INTEREST 0\n#define DATA_AGGREGATION_LEVEL 1\n#define DATA_SAMPLING_RATE 0\n",
579583
},
580584
}
581585

0 commit comments

Comments
 (0)