Skip to content

Tests: no network calls! - #1975

Closed
dscho wants to merge 1 commit into
mainfrom
no-network-calls
Closed

Tests: no network calls!#1975
dscho wants to merge 1 commit into
mainfrom
no-network-calls

Conversation

@dscho

@dscho dscho commented Aug 15, 2025

Copy link
Copy Markdown
Member

As promised, this is my next attempt at removing network calls during tests (so that they would pass even when stuck in a plane without internet connection).

@dscho
dscho requested a review from webstech August 15, 2025 21:55
@dscho dscho self-assigned this Aug 15, 2025

@webstech webstech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In PR #1786 you removed the remote access in git-notes.test.ts by adding insteadof to the config. Is there a reason to do this as well? The tests run fine no matter what the value of gitURL is.

@dscho

dscho commented Aug 16, 2025

Copy link
Copy Markdown
Member Author

In PR #1786 you removed the remote access in git-notes.test.ts by adding insteadof to the config. Is there a reason to do this as well? The tests run fine no matter what the value of gitURL is.

Oh wow, you're right! No, it is not necessary. I simply forgot (apparently I fixed the same problem several times over the years... 🤦).

When testing whether a given `/allow` command yields the expected
result, let's mock out the actual GitHub REST API call.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho
dscho force-pushed the no-network-calls branch from 30be28d to 68a8efc Compare August 16, 2025 22:37
Comment thread tests/ci-helper.test.ts
};

ci.setGHGetPRComment(comment);
ci.letGHGetGitHubUserInfoThrow("is not a valid GitHub username");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test was originally intended to verify this line was run in CIHelper:

                    throw new Error(`User ${accountName} is not a valid GitHub username: ${reason}`);

Running the tests locally, the error is Error: User bad_@@@@ is not a valid GitHub username: Error: Need a GitHub token for gitgitgadget, which has as the reason an error thrown by GitHubGlue (and no network access). If you want to verify there is no network while still allowing the original test, how about:

   const noNetwork = "No net";
   ci.letGHGetGitHubUserInfoThrow(noNetwork);
   await ...
   expect ...
   expect(ci.addPRCommentCalls[0][1]).toMatch(noNetwork); // new test for no network access

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh wow, never mind! I must have been in a situation when I developed the patch originally where I had lost network access (being happy about Git's distributed nature!). However, I just reran the test suite after disconnecting from the network, and it all passed:

Test Suites: 26 passed, 26 total
Tests:       152 passed, 152 total
Snapshots:   0 total
Time:        115.744 s, estimated 116 s
Ran all test suites.

I should have verified whether this patch is still needed before opening this PR, but I keep forgetting that when rebasing branch thickets, sorry!!!

@dscho

dscho commented Aug 20, 2025

Copy link
Copy Markdown
Member Author

This patch is not actually needed to run the test suite without network access. Sorry for the noise!

@dscho dscho closed this Aug 20, 2025
@dscho
dscho deleted the no-network-calls branch August 21, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants