Skip to content

Better Handle Empty Tables #1228

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Better Handle Empty Tables #1228

wants to merge 6 commits into from

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented May 1, 2025

what

Identified issues when considering that the table is "empty"

why

Added full tests for utils and empty table cases
Making sure we validate the places where we are using these utils pkg and block future regressions

references

Summary by CodeRabbit

  • Bug Fixes

    • Improved output handling for metadata and settings listings, ensuring results are returned consistently without additional empty output checks or messages.
  • Tests

    • Added comprehensive unit tests for utility functions to verify component existence checks and error identification, covering various scenarios and edge cases.

@github-actions github-actions bot added the size/m label May 1, 2025
@Cerebrovinny Cerebrovinny added minor New features that do not break anything and removed size/m labels May 1, 2025
@github-actions github-actions bot added the size/m label May 1, 2025
Copy link

codecov bot commented May 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 33.60%. Comparing base (f26dfe1) to head (fc29a5e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1228      +/-   ##
==========================================
+ Coverage   33.56%   33.60%   +0.03%     
==========================================
  Files         226      226              
  Lines       24219    24205      -14     
==========================================
+ Hits         8130     8133       +3     
+ Misses      14875    14858      -17     
  Partials     1214     1214              
Flag Coverage Δ
unittests 33.60% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@Cerebrovinny Cerebrovinny marked this pull request as ready for review May 1, 2025 10:07
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner May 1, 2025 10:07
@Cerebrovinny Cerebrovinny requested review from osterman, milldr and aknysh May 2, 2025 15:05
Comment on lines 23 to 34
lines := strings.Split(output, "\n")

// Remove empty lines
var nonEmptyLines []string
for _, line := range lines {
if strings.TrimSpace(line) != "" {
nonEmptyLines = append(nonEmptyLines, line)
}
}

// A table is empty if it has 2 or fewer non-empty lines (header and separator)
return len(nonEmptyLines) <= 2
Copy link
Member

Choose a reason for hiding this comment

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

It seems odd to me we have this function to begin with. A table is empty if it has no data, and data is fed to the table presumably. Why are we addressing the symptom "A table is empty if it has 2 or fewer non-empty lines (header and separator)" rather than the cause?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree actually I found a better approach to remove that and directly return the correct result in the FilterAndListValues

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so we already have listerrors.NoValuesFoundError and also tests for that we can just delete it

@osterman osterman changed the title Utils improvements and new tests Better Handle Empty Tables May 2, 2025
Copy link

mergify bot commented May 2, 2025

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label May 2, 2025
Copy link
Contributor

coderabbitai bot commented May 2, 2025

📝 Walkthrough

Walkthrough

The changes remove the IsEmptyTable function from the utility package and eliminate its usage in the listMetadata and listSettings command files. Now, these commands return their output directly without checking for empty or "empty table" results. Additionally, a new test file is introduced to cover utility functions, specifically focusing on error type identification and component existence logic, with comprehensive test cases for various scenarios.

Changes

File(s) Change Summary
cmd/list_metadata.go, cmd/list_settings.go Removed import and usage of the IsEmptyTable utility; now directly return output without extra empty checks or logging.
pkg/list/utils/utils.go Removed the IsEmptyTable function.
pkg/list/utils/utils_test.go Added new tests for utility functions, covering error identification and component existence logic with multiple scenarios.

Suggested labels

patch

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title 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.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
pkg/list/utils/utils_test.go (1)

139-180: Good test case coverage for component existence.

The test cases effectively cover existing components, path-based components, non-existent components, ignored section components, and empty component names.

Consider adding one more test case for a deeply nested path (e.g., "path/to/deeper/comp-a") to ensure the extraction of the base component name works correctly with arbitrary path depths.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c87cd51 and c0a8616.

📒 Files selected for processing (4)
  • cmd/list_metadata.go (0 hunks)
  • cmd/list_settings.go (0 hunks)
  • pkg/list/utils/utils.go (0 hunks)
  • pkg/list/utils/utils_test.go (1 hunks)
💤 Files with no reviewable changes (3)
  • pkg/list/utils/utils.go
  • cmd/list_settings.go
  • cmd/list_metadata.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/list/utils/utils_test.go (2)
pkg/list/errors/types.go (1)
  • NoValuesFoundError (9-12)
pkg/list/utils/utils.go (1)
  • IsNoValuesFoundError (12-15)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/list/utils/utils_test.go (5)

13-24: Well-structured mock for error type testing.

Good approach for creating a mock error type. The implementation correctly implements the Error interface, which is essential for testing type assertions against the actual NoValuesFoundError.


26-61: Comprehensive test coverage for IsNoValuesFoundError.

The table-driven test approach is solid, covering all critical scenarios including custom mock errors, standard errors, nil errors, and actual NoValuesFoundError instances. This ensures the function correctly identifies only the specific error type it should match.


63-138: Well-implemented test logic for component existence checks.

The helper function effectively mimics the core processing loop of CheckComponentExists. The detailed comments on each line explaining which part of the original function is being covered show thoughtful test design.


68-105: Thorough test data covering various scenarios.

Your simulated stack map covers an excellent range of scenarios: valid structures, malformed data at different levels, and edge cases. This comprehensive approach ensures the component existence logic is thoroughly tested.


1-11: Proper package and import structure.

The test package is correctly named with the _test suffix and imports the necessary dependencies. Using the testify/assert package makes the tests more readable.

@Cerebrovinny Cerebrovinny requested a review from osterman May 5, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything needs-cloudposse Needs Cloud Posse assistance size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants