Skip to content

Add unit tests for the custom plugin monitor - #1330

Open
DigitalVeer wants to merge 1 commit into
kubernetes:masterfrom
DigitalVeer:cpm-generate-status-tests
Open

Add unit tests for the custom plugin monitor#1330
DigitalVeer wants to merge 1 commit into
kubernetes:masterfrom
DigitalVeer:cpm-generate-status-tests

Conversation

@DigitalVeer

@DigitalVeer DigitalVeer commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This PR bumps the unit test coverage for custom plugin monitor from 0.8% to 95.3%


This PR adds tests for generateStatus, the monitor lifecycle and the metrics path.

This is the first item of #1328.

Package Before After
pkg/custompluginmonitor 0.8% 95.3%

What the tests check

  • TestGenerateStatusForConditions replays plugin results
    against one monitor and checks the condition and the event after each step for five scenarios.

  • TestGenerateStatusForTemporaryProblem checks that a temporary rule creates an event and
    moves no condition.

  • TestGenerateStatusMetrics checks the problem counter and the problem gauge through the
    existing metrics stub. The counter increments for new problems only.

  • TestMonitorLoopReportsPluginResults and TestMonitorLoopExitsWhenResultChannelCloses
    check the goroutine lifecycle. Stop must return. A closed result channel must end the
    loop.

  • TestNewCustomPluginMonitorOrDie writes a config file and checks that the constructor
    applies the defaults.

The lifecycle tests use the plugin scripts in pkg/custompluginmonitor/plugin/test-data.

Validation

Check Result
go test -cover ./pkg/custompluginmonitor/ 95.3%
go test -timeout=1m -race -short -count=5 pass, 3.6s
golangci-lint run --config .golangci.yml 0 issues

This change adds tests for generateStatus, the monitor lifecycle and the
metrics path. Package coverage increases from 0.8% to 95.3% of statements.

A table test replays sequences of plugin results against one monitor. The
table covers the five condition scenarios in generateStatus. Other tests
cover the temporary rule path, the problem counter, the problem gauge and
the constructor.

This change adds no production code.
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 29, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @DigitalVeer. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 29, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DigitalVeer
Once this PR has been reviewed and has the lgtm label, please assign random-liu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant