test(images): assert that a cached image is served, not that something happened - #924
Open
m4bard wants to merge 1 commit into
Open
test(images): assert that a cached image is served, not that something happened#924m4bard wants to merge 1 commit into
m4bard wants to merge 1 commit into
Conversation
…g happened
Nine of the twelve ImagesController test files ended with:
if (result is PhysicalFileResult fileResult)
{
Assert.Equal(fullPath, fileResult.FileName);
}
else
{
Assert.IsType<NotFoundObjectResult>(result);
}
Both branches pass, so the test succeeded whether the image was served or the
endpoint returned 404. Two of the nine say in their own names that they cover
serving, GetImage_TriggersMetadataDownload_AndServesCachedImage and
GetImage_WhenTempExists_AndAudiobookExists_MovesToLibraryAndServesLibraryFile,
and both passed with serving removed. What was covered was the lookup path.
Each of the nine creates the file it then asks for, so serving it is the only
correct outcome and the permissive form was not buying anything. They now assert
the type outright.
The comment they carried, "Expect either PhysicalFileResult when file exists or
NotFound if it wasn't found", described a condition the test itself controls.
Replaced with a note about why the strict form is the right one.
Checked by replacing the cached-image return in ImageResponseBuilder with a flat
404, which is the control from the issue. Before this change 2 of 12 failed.
After it, 11 of 12 fail. The twelfth is ImagesController_PlaceholderFallbackTests,
which asserts on the placeholder return further down and is correctly out of
scope for that control.
Each test file already uses its own content root under the temp directory, so
asserting strictly does not make them order-dependent on each other.
No production code changes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YEVQ7qDJLk5196MFeggWuA
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.
Fixes #897.
Nine of the twelve
ImagesControllertest files ended with the same shape:Both branches pass, so the test succeeded whether the image was served or the endpoint returned 404. Two of the nine say in their own names that they cover serving,
GetImage_TriggersMetadataDownload_AndServesCachedImageandGetImage_WhenTempExists_AndAudiobookExists_MovesToLibraryAndServesLibraryFile, and both passed with serving removed. What was covered was the lookup path.Each of the nine creates the file it then asks for, so serving it is the only correct outcome and the permissive form was not buying anything. They now assert the type outright.
The comment they carried, "Expect either PhysicalFileResult when file exists or NotFound if it wasn't found", described a condition the test itself controls. It is replaced with a note on why the strict form is the right one.
The check
I re-ran the control from the issue: the cached-image return in
ImageResponseBuilderreplaced with a flat 404, so every path through the builder fails.Before this change, 2 of 12 failed. After it, 11 of 12 fail. The twelfth is
ImagesController_PlaceholderFallbackTests, which asserts on the placeholder return further down and is correctly out of scope for that control.Each test file already uses its own content root under the temp directory, so asserting strictly does not make them depend on each other's order.
No production code changes.
Worked through with Claude Code at my direction. The claims above were checked by running them rather than by reading, and I reviewed this before posting.