test(storage): migrate StorageTests to Swift Testing (Phase 3)#1096
Open
grdsdev wants to merge 1 commit into
Open
test(storage): migrate StorageTests to Swift Testing (Phase 3)#1096grdsdev wants to merge 1 commit into
grdsdev wants to merge 1 commit into
Conversation
Converts all 11 files in Tests/StorageTests from XCTest+Mocker to Swift Testing (@Suite/@test) + Replay for HTTP mocking, per the SDK-435 migration plan and the Phase 0 conventions decided in SDK-1247. - Adds the Replay package dependency and wires it into the StorageTests target; drops Mocker/TestHelpers (only used for the now-removed .snapshotRequest curl-snapshot assertions, dropped per plan with no shim). - Moves StorageTests out of the blanket Swift 5 language-mode pin into full Swift 6 mode, matching production targets' strict-concurrency settings. - StorageHTTPSession already supported fetch/upload closure injection (same pattern as FunctionsClient), so no new Storage-side scope was needed for Replay adoption. - Adds request-body verification via Replay's `.custom` matcher for move/copy/remove (previously covered by .snapshotRequest), reading the body via httpBodyStream since URLSession no longer exposes it on httpBody once handed to the loading system. Linear: SDK-1250
Contributor
|
spydon
approved these changes
Jul 8, 2026
Coverage Report for CI Build 28976348844Coverage remained the same at 83.221%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
grdsdev
added a commit
that referenced
this pull request
Jul 9, 2026
Converts the largest AuthTests file (87 tests, 81 Mocker Mock() calls, 53 curl-snapshot assertions) to Swift Testing + Replay, per the Phase 0 decision (SDK-1247) and the Phase 4/Phase 3 conversion patterns (PostgRESTTests PR #1095, StorageTests PR #1096). - Curl-snapshot request-shape assertions dropped per the Phase 0 "no shim" decision, replaced by Replay's matcher-based enforcement. - Query strings preserved via exact-URL matching (.method, .url) rather than path-only matching, so query-string regressions are still caught (the gap PR #1095's follow-up commit found and fixed). - Request bodies verified via a custom .custom matcher that decodes both sides as AnyJSON for structural comparison (key order/whitespace insensitive), following the pattern from StorageTests PR #1096's jsonBody(of:) helper -- important here since most of this file's Mocker bodies carry auth-relevant payloads (passwords, tokens, PKCE code verifiers, MFA/passkey credentials). - withMainSerialExecutor wrapping moved from XCTestCase.invokeTest into the handful of @test bodies that actually spawn concurrent authStateChanges-driven Tasks. - HTTPResponse.stub(...) helper (used cross-file by SessionManagerTests) preserved at the bottom of the file. Linear: SDK-1252
4 tasks
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
Migrates
Tests/StorageTests(11 files) from XCTest+Mocker to Swift Testing (@Suite/@Test) + Replay for HTTP mocking, per the repo-wide Swift Testing migration plan (SDK-435) and the conventions decided in Phase 0 (SDK-1247, SDK-1091).Changes
Replaypackage dependency, wired into theStorageTeststarget. RemovedMocker/TestHelpersdeps (only used for the now-dropped.snapshotRequestcurl-snapshot assertions — dropped per the ticket's explicit "no shim" decision). MovedStorageTestsout of the blanket.swiftLanguageMode(.v5)pin into theswift6TestTargetsset, so it now compiles under full Swift 6 language mode with the same strict-concurrency settings as production targets.BucketOptionsTests,FileOptionsTests,TransformOptionsTests,ValueTypesTests,StorageErrorTests,MultipartFormDataTests) are mechanical conversions.DownloadBehaviorTests'setUpbecameinit(). The Mocker-heavy files (StorageBucketAPITests,StorageFileAPITests) now use@Test(.replay(stubs: [...]))withStorageHTTPSession(fetch: { try await Replay.session.data(for: $0) }, ...)injected — mirroringFunctionsClient's existing fetch-closure DI pattern, so no new Storage-side injection scope was needed.SupabaseStorageTestskeeps its existing closure-basedStorageHTTPSessionmocking (already framework-agnostic) but dropsXCTestCase..snapshotRequest's curl-body assertions had no direct Replay equivalent for inline stubs, somove/copy/remove(the tests most exposed to a silent parameter-swap regression, e.g.sourceKey/destinationKey) now use a.customReplay matcher that decodes and compares the JSON body. Verified this actually catches regressions by temporarily swappingsourceKey/destinationKeyinStorageFileApi.move()and confirming the test fails, then reverting.StorageBucketAPITests-testCreateBucket.1.txt, didn't match any current test) removed.Root cause note (bug found during migration)
While migrating
SupabaseStorageTests.uploadData/uploadFileURL, found that the original XCTest mocks wired their response-producing closure toStorageHTTPSession.fetch, not.upload— confirmed this is correct because productionStoragecode (StorageApi.swift) only ever callsconfiguration.session.fetch;.uploadis currently dead code for all Storage HTTP calls including multipart uploads. My first conversion pass mistakenly moved the mock logic onto.upload, causing anunimplemented()failure — fixed by keeping the response logic on.fetch.Test plan
swift build --build-tests: clean, no warnings beyond pre-existing intentional deprecated-API test warnings.swift test --filter StorageTests: 139/139 tests pass (138 original XCTest methods + 1, from splitting a 10-case for-loop into two@Test(arguments:)parameterized tests covering the same 10 cases).swift test(full suite): 0 failures outsideIntegrationTests(which requires a local Supabase instance perAGENTS.md, pre-existing/expected withoutsupabase start).import XCTest/import Mockerremaining inTests/StorageTests(grep-verified)../scripts/format.shand./scripts/spell-check.shclean.sourceKey/destinationKeyinmove(), confirmed the new body-matching test fails, then reverted.Linear
Closes SDK-1250