Skip to content

test(storage): add comprehensive file operation tests#130

Merged
demolaf merged 44 commits intonextfrom
storage-file-test
Jan 29, 2026
Merged

test(storage): add comprehensive file operation tests#130
demolaf merged 44 commits intonextfrom
storage-file-test

Conversation

@demolaf
Copy link
Member

@demolaf demolaf commented Jan 27, 2026

Adds comprehensive integration and unit tests for BucketFile operations

Changes

  • Add StorageHttpClient that routes requests based on compression needs:
  • Storage API requests use manual decompression (enables checksum validation on compressed data)
  • Auth/OAuth endpoints use auto-decompression for JSON parsing
  • Prevent adding errors to closed sink in upload stream completion (createWriteStream)

…ons`

This commit introduces two new properties to `StorageOptions`:
- `credentials`: Allows passing service account credentials directly as an object.
- `keyFilename`: Allows specifying a path to a service account JSON key file.

This provides more explicit ways to configure authentication, alongside the existing `authClient` option and Application Default Credentials (ADC). The authentication client initialization logic has been updated to prioritize credentials in the following order: `authClient`, `credentials`, `keyFilename`, and finally ADC.
…tream validation

- Refactor HmacKey tests to allow null and empty projectId, and verify correct metadata assignment
- Update error expectations to use ArgumentError and consistent error messages
- Enhance hash_stream_validator tests to use stream.drain and explicit error assertions
- Wrap integration and endpoint tests in runZoned to isolate environment variables
…ionality

- Add `storage_example.dart` demonstrating basic usage and signed URL generation
- Update `main.dart` to include storage example
- Add end-to-end tests for signed URL upload, download, and expiration in `file_integration_test.dart`
- Update integration tests to use production bucket name
- Implement Storage service with singleton pattern and FirebaseApp integration
- Add support for Firebase Storage emulator via FIREBASE_STORAGE_EMULATOR_HOST
- Introduce EmulatorClient to handle emulator authentication
- Update environment utilities for Storage emulator detection and configuration
- Enhance Service class to manage emulator and production clients, including proper termination
- Refactor storage example to use new Storage service API
- Update exports and imports for new storage structure
- Add emulator configuration to run_with_emulator.sh
- Improve resumable upload handling for emulator compatibility
Adds a new `Storage` service to the Firebase Admin SDK. This service provides an interface to Google Cloud Storage.

Key features:
- Integration with the Firebase Storage emulator via `FIREBASE_STORAGE_EMULATOR_HOST`.
- `app.storage()` method to access the storage service.
- Unit and integration tests for the new service.
…s class

- Replace custom Credentials class with GoogleCredential from googleapis_auth_utils
- Update StorageOptions to accept GoogleCredential directly
- Remove keyFilename and related logic in favor of unified credential handling
- Refactor integration and unit tests to use GoogleCredential.fromServiceAccount
- Update imports to use package aliases for clarity
- Increase delay in integration tests to improve consistency
Adds a full suite of unit tests for the `File` class, covering core operations, metadata handling, and access control.

This includes tests for:
- `getMetadata`
- `setMetadata`
- `delete`
- `exists`
- `get`
- `copy`
- `move`
- `rename`
- `makePublic`
- `makePrivate`
- `publicUrl`
- `getSignedUrl`

The tests use a mock-based setup to verify API interactions, option passing (like `userProject` and preconditions), and correct handling of both success and error responses from the underlying storage API.
@demolaf demolaf marked this pull request as draft January 27, 2026 16:23
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

Coverage Report

✅ Coverage 63.61% meets 40% threshold

Total Coverage: 63.61%
Lines Covered: 6177/9711

Package Breakdown

Package Coverage
dart_firebase_admin 70.01%
googleapis_firestore 73.44%
googleapis_auth_utils 70.57%
googleapis_storage 44.83%

Minimum threshold: 40%

Introduces `StorageHttpClient`, a custom `http.BaseClient` that directs traffic to one of two underlying clients based on the request URL.

This change is necessary because:
- OAuth and token requests require automatic decompression to handle JSON responses.
- Google Cloud Storage API requests need decompression disabled to allow for manual data integrity checks (like CRC32C).

The new client is now used as the base client for authentication and subsequent API calls.
- Add integration tests for `makePublic`, `makePrivate`, `publicUrl`, and `get` methods on `BucketFile`
- Add comprehensive unit tests for `createWriteStream` covering:
    - Resumable and simple upload configurations
    - Content-type detection and manual overrides
    - Gzip compression logic (auto-detection and explicit settings)
    - Precondition and validation options (CRC32C, MD5)
    - Metadata and ACL handling (`private`, `public`, `predefinedAcl`)
    - HTTP-level behavior including progress reporting, metadata updates, and error handling
- Improve test coverage for upload URI handling and project-based billing options
…, and cloud tasks

- Introduce Environment class for type-safe emulator host retrieval
- Refactor storage, auth, and cloud tasks clients to use Environment methods
- Update tests to use Environment constants for emulator host
@demolaf demolaf changed the title File e2e tests test(storage): add comprehensive file operation tests Jan 28, 2026
@demolaf demolaf marked this pull request as ready for review January 28, 2026 13:12
…ploads

- Implement File.generateSignedPostPolicyV2 and File.generateSignedPostPolicyV4 methods
- Add types for signed POST policy options and outputs
- Provide argument validation and error handling for policy generation
- Add integration and unit tests for signed POST policy methods
Base automatically changed from admin-storage-wrapper to next January 29, 2026 09:55
@demolaf demolaf merged commit d71e331 into next Jan 29, 2026
9 checks passed
@demolaf demolaf deleted the storage-file-test branch January 29, 2026 15:02
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