Add unit tests for modules/subreddit (0% → 98.6% coverage) - #2166
Open
Seanstoppable wants to merge 1 commit into
Open
Add unit tests for modules/subreddit (0% → 98.6% coverage)#2166Seanstoppable wants to merge 1 commit into
Seanstoppable wants to merge 1 commit into
Conversation
Add comprehensive tests covering: - GetLinks API: URL construction, sort modes, top time periods, User-Agent header - HTTP error handling: 4xx/5xx status codes, connection errors, invalid JSON - Link/RedditDocument JSON parsing with edge cases - Widget content rendering: title format, error display, link formatting - Widget Refresh: numberOfPosts truncation, fewer-than-requested, errors - Widget openLink/openReddit: valid/invalid selection, nil links - Settings: YAML parsing with defaults, all field overrides - ConfigText output Uses net/http/httptest with table-driven tests throughout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive unit tests for
modules/subreddit, bringing statement coverage from 0% to 98.6%.Test Files
subreddit_test.go— Tests forGetLinksAPI function:widget_test.go— Tests for widget display logic:content()rendering: title format, error display, link formatting, special character escapingRefresh(): numberOfPosts truncation, fewer-than-requested, exact count, error pathsopenLink()/openReddit(): valid selection, invalid selection, nil links, out-of-boundssettings_test.go— Tests for YAML settings parsing:ConfigText()outputApproach
Uses
net/http/httptestto mock the Reddit JSON API by overriding the package-levelrootPagevariable. All tests are table-driven.