Skip to content

graph: replace fatal assertions and simplify test helpers#10609

Merged
ellemouton merged 5 commits intolightningnetwork:masterfrom
ellemouton:graph-unit-test-cleanup
Feb 25, 2026
Merged

graph: replace fatal assertions and simplify test helpers#10609
ellemouton merged 5 commits intolightningnetwork:masterfrom
ellemouton:graph-unit-test-cleanup

Conversation

@ellemouton
Copy link
Copy Markdown
Collaborator

@ellemouton ellemouton commented Feb 25, 2026

  • Convert graph/ and graph/db/ tests from t.Fatal*/FailNow* patterns to direct require assertions.
  • Refactor helper functions to assert internally with t.Helper() and return only concrete values (randEdgePolicy, createChannelEdge, compareEdgePolicies).
  • Update all call sites accordingly; lint passes after each helper-focused commit.

@ellemouton ellemouton self-assigned this Feb 25, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @ellemouton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the testing infrastructure within the graph/ and graph/db/ packages. The primary goal was to standardize error handling in tests by adopting stretchr/testify/require assertions, moving away from manual t.Fatal calls. Additionally, test helper functions were streamlined to encapsulate error handling, making them easier to use and reducing boilerplate code at their call sites. These changes enhance the maintainability and clarity of the test suite.

Highlights

  • Test Assertion Modernization: Converted numerous t.Fatal* and t.FailNow* patterns in graph/ and graph/db/ tests to direct require assertions from the stretchr/testify library, improving test readability and robustness.
  • Test Helper Refactoring: Refactored test helper functions such as randEdgePolicy, createChannelEdge, and compareEdgePolicies to internally handle assertions using t.Helper() and return only concrete values, simplifying their call sites.
  • Code Simplification: Removed redundant error checks and reflect and runtime imports in several test files, leading to cleaner and more concise test code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • graph/builder_test.go
    • Updated createChannelEdge calls to pass t as an argument and remove error return values.
    • Replaced t.Fatalf and if err != nil checks with require.NoError, require.Truef, require.False, and require.EqualValues assertions.
    • Simplified assertChannelsPruned logic using require assertions.
  • graph/db/addr_test.go
    • Removed unused strings import.
    • Replaced switch statement for error handling with require.Error, require.ErrorContains, and require.NoError.
  • graph/db/channel_cache_test.go
    • Removed unused reflect import.
    • Added github.com/stretchr/testify/require import.
    • Replaced t.Fatalf checks with require.False, require.Equal, and require.True assertions.
  • graph/db/graph_test.go
    • Removed unused reflect and runtime imports.
    • Replaced t.Fatalf calls with require.Truef(t, false, ...) for unreachable code paths.
    • Converted numerous manual error checks and comparisons to require.NoError, require.Len, require.Equal, require.False, require.True, require.Zero, and require.Empty assertions.
    • Modified compareEdgePolicies to accept t testing.TB and use t.Helper() and require.Equal internally.
  • graph/db/reject_cache_test.go
    • Removed unused reflect import.
    • Added github.com/stretchr/testify/require import.
    • Replaced t.Fatalf checks with require.False, require.Equal, and require.True assertions.
  • graph/notifications_test.go
    • Modified randEdgePolicy and createChannelEdge helper functions to accept t testing.TB, use t.Helper(), and handle errors internally with require.NoError.
    • Replaced t.Fatal calls with require.Truef(t, false, ...) for test failures.
    • Converted various if conditions and t.Fatalf calls to require.NoError, require.Len, require.True, require.Equal, and require.EqualValues assertions.
Activity
  • The pull request author, ellemouton, created this PR to improve test quality and maintainability.
  • The changes primarily involve refactoring existing test code to use modern Go testing practices and assertion libraries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@lightninglabs-deploy lightninglabs-deploy added the severity-low Best-effort review label Feb 25, 2026
@lightninglabs-deploy
Copy link
Copy Markdown
Collaborator

🟢 PR Severity: LOW

Automated classification | 6 files | 0 lines changed (non-test)

🟢 Low (6 files)
  • graph/builder_test.go - test file (*_test.go)
  • graph/db/addr_test.go - test file (*_test.go)
  • graph/db/channel_cache_test.go - test file (*_test.go)
  • graph/db/graph_test.go - test file (*_test.go)
  • graph/db/reject_cache_test.go - test file (*_test.go)
  • graph/notifications_test.go - test file (*_test.go)

Analysis

This PR is a test-only change. All 6 modified files are *_test.go files located under the graph/ package (including graph/db/). Per the severity classification rules, test-only changes (*_test.go) qualify as LOW severity.

No non-test, non-generated files were changed, so no severity bump rules apply (0 non-test files, 0 non-test lines changed).

The changes appear to be refactoring or cleanup of existing graph-related tests, with a net reduction of 510 lines across 6 test files, suggesting test simplification or consolidation.


To override, add a severity-override-{critical,high,medium,low} label.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors tests in graph/ and graph/db/ to consistently use the testify/require package for assertions, replacing t.Fatal* and manual if err != nil checks. It also simplifies several test helper functions (randEdgePolicy, createChannelEdge, compareEdgePolicies) by making them perform assertions internally and removing error return values. The changes significantly improve the readability and conciseness of the test code. The refactoring is well-executed and follows best practices for testing in Go.

@ellemouton ellemouton force-pushed the graph-unit-test-cleanup branch from 0e69874 to fa2d502 Compare February 25, 2026 07:49
Copy link
Copy Markdown
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM! Readability ftw! ✨

Comment thread graph/builder_test.go Outdated
Comment thread graph/notifications_test.go
Copy link
Copy Markdown
Collaborator

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM, nice improvements 🎉

Comment thread graph/db/graph_test.go
Comment thread graph/notifications_test.go Outdated
Replace remaining fatal-style assertions in graph/db tests with direct
testify/require helpers. This simplifies control flow and reduces
indentation by using NoError, True/False, Equal, Len, Empty, and Nil
assertions directly.
Replace remaining fatal-style assertions in graph package tests with
direct testify/require helpers. This simplifies control flow and makes
test intent clearer by using NoError, True/False, Len, Empty, and
Equal/EqualValues assertions.

Also remove FailNow-style patterns in favor of specific assertion
helpers.
Update randEdgePolicy to take a testing handle, mark itself as a
helper, and assert internal packing errors directly with require.

Call sites now receive only the policy value without plumbing an
error through immediate require.NoError checks.
Update createChannelEdge to take a testing handle, mark itself as a
helper, and call require.NoError for funding script generation.

All call sites now consume only returned values and no longer plumb
an immediately-asserted error value.
Convert compareEdgePolicies into a test helper that accepts a
testing handle and performs assertions directly.

Update call sites to invoke the helper instead of threading errors
into immediate require.NoError checks.
@ellemouton ellemouton force-pushed the graph-unit-test-cleanup branch from fa2d502 to 160c2a9 Compare February 25, 2026 09:36
@ellemouton ellemouton enabled auto-merge February 25, 2026 09:37
@ellemouton ellemouton merged commit 13a8356 into lightningnetwork:master Feb 25, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants