Skip to content

NO-JIRA: chore(tests): reduce the code duplication in runtime tests #636

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jstourac
Copy link
Member

@jstourac jstourac commented Jun 25, 2025

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Summary by CodeRabbit

  • Refactor
    • Improved test structure and maintainability by consolidating repeated logic into helper functions and enhancing setup/teardown procedures.
  • Tests
    • Enhanced test coverage for Notebook resource behavior, including scenarios involving ConfigMap and ImageStream resources.
    • Improved clarity and robustness of test cases by simplifying structures and making error handling more consistent.

Copy link

openshift-ci bot commented Jun 25, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

openshift-ci bot commented Jun 25, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@openshift-ci openshift-ci bot added the size/xl label Jun 25, 2025
@jstourac jstourac requested a review from jiridanek June 25, 2025 12:37
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

A new common.go file introduces helper functions for creating Notebook, ConfigMap, and ImageStream resources. The test files are refactored to use these helpers, with duplicate logic removed and a new helper for asserting Notebook volume and mount presence. Test coverage and resource cleanup logic are improved.

Changes

File(s) Change Summary
components/odh-notebook-controller/controllers/common.go New file with helper functions to create Notebook, ConfigMap, and ImageStream objects.
components/odh-notebook-controller/controllers/notebook_controller_test.go Removed local createNotebook helper, likely replaced by the new shared helper in common.go.
components/odh-notebook-controller/controllers/notebook_runtime_test.go Refactored tests: added helper for asserting volumes/mounts, improved test structure, expanded ImageStream coverage.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Helper as common.go Helpers
    participant K8s as Kubernetes API

    Test->>Helper: createNotebook(name, namespace)
    Helper->>K8s: Construct Notebook resource
    Test->>Helper: createRuntimeConfigMap(name, namespace, data)
    Helper->>K8s: Construct ConfigMap resource
    Test->>Helper: createRuntimeImageStream(name, namespace, tags)
    Helper->>K8s: Construct ImageStream resource
    Test->>K8s: Apply resources, verify state
Loading

Suggested labels

approved, lgtm, size/l

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.14%. Comparing base (24d1e27) to head (2866b08).

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #636       +/-   ##
===========================================
+ Coverage   58.08%   70.14%   +12.06%     
===========================================
  Files          11       10        -1     
  Lines        3075     2164      -911     
===========================================
- Hits         1786     1518      -268     
+ Misses       1132      523      -609     
+ Partials      157      123       -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jiridanek
Copy link
Member

I guess? it is almost impossible to me to match up the code reorg in the diff view. I'll try fancy diff.

@jiridanek
Copy link
Member

still can't make sense of it even with fancy diff webui tool

@jiridanek
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Jun 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@openshift-ci openshift-ci bot added size/xl and removed size/xl labels Jun 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
components/odh-notebook-controller/controllers/common.go (1)

10-30: Consider documenting the choice of default container image.

The function uses a hardcoded UBI8 image. While this is acceptable for test helpers, consider adding a comment explaining why this specific image was chosen as the default for tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24d1e27 and 2866b08.

📒 Files selected for processing (3)
  • components/odh-notebook-controller/controllers/common.go (1 hunks)
  • components/odh-notebook-controller/controllers/notebook_controller_test.go (0 hunks)
  • components/odh-notebook-controller/controllers/notebook_runtime_test.go (2 hunks)
💤 Files with no reviewable changes (1)
  • components/odh-notebook-controller/controllers/notebook_controller_test.go
🧰 Additional context used
🧠 Learnings (1)
components/odh-notebook-controller/controllers/notebook_runtime_test.go (1)
Learnt from: jiridanek
PR: opendatahub-io/kubeflow#623
File: components/odh-notebook-controller/controllers/notebook_runtime_test.go:179-179
Timestamp: 2025-06-25T06:54:57.600Z
Learning: In the file `components/odh-notebook-controller/controllers/notebook_runtime_test.go`, there is a suggestion to repurpose `testCase.ConfigMap` as `expectedConfigMap` in the test structure to improve clarity by separating input from expected results. This improvement is deferred to be addressed as part of GitHub issue #634.
🔇 Additional comments (6)
components/odh-notebook-controller/controllers/common.go (2)

32-45: LGTM!

The ConfigMap helper is well-implemented and suitable for test usage.


47-68: LGTM!

The ImageStream helper correctly sets up the required labels and lookup policy for runtime image testing.

components/odh-notebook-controller/controllers/notebook_runtime_test.go (4)

21-28: Good refactoring to follow Go naming conventions.

The constants have been properly renamed to use idiomatic Go camelCase instead of underscore_case.


30-73: Excellent refactoring to reduce code duplication.

The new helper function effectively consolidates the repeated logic for checking Notebook volumes and mounts. The use of Eventually with proper timeout handling and the boolean parameter for expected state makes the tests more maintainable and readable.


78-136: Well-structured test refactoring with improved cleanup logic.

The test has been improved with:

  • Simplified test case structure focusing on relevant fields
  • Robust cleanup logic that waits for resource deletion
  • Effective use of the new helper functions

The addition of Eventually checks for resource deletion in BeforeEach prevents potential race conditions between tests.


138-290: Excellent addition of comprehensive ImageStream test coverage.

The new test group provides thorough coverage for ImageStream-driven ConfigMap creation and mounting scenarios. The test cases effectively cover:

  • Multiple valid runtime image tags
  • Single valid tag
  • Irrelevant metadata (negative test case)

The tests properly validate both ConfigMap content and Notebook mounting behavior.

@jiridanek
Copy link
Member

/lgtm

rabbit is happy, so who am I to argue

@openshift-merge-robot
Copy link

PR needs rebase.

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.

@openshift-merge-robot openshift-merge-robot added the needs-rebase The PR needs a rebase or there are conflicts label Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress lgtm needs-rebase The PR needs a rebase or there are conflicts size/xl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants