@@ -3,12 +3,12 @@ import Mocker
33import TestHelpers
44import XCTest
55
6+ @testable import Storage
7+
68#if canImport(FoundationNetworking)
79 import FoundationNetworking
810#endif
911
10- @testable import Storage
11-
1212final class StorageBucketAPITests : XCTestCase {
1313 let url = URL ( string: " http://localhost:54321/storage/v1 " ) !
1414 var storage : SupabaseStorageClient !
@@ -47,6 +47,60 @@ final class StorageBucketAPITests: XCTestCase {
4747 Mocker . removeAll ( )
4848 }
4949
50+ func testURLConstruction( ) {
51+ let urlTestCases = [
52+ (
53+ " https://blah.supabase.co/storage/v1 " ,
54+ " https://blah.storage.supabase.co/storage/v1 " ,
55+ " update legacy prod host to new host "
56+ ) ,
57+ (
58+ " https://blah.supabase.red/storage/v1 " ,
59+ " https://blah.storage.supabase.red/storage/v1 " ,
60+ " update legacy staging host to new host "
61+ ) ,
62+ (
63+ " https://blah.storage.supabase.co/storage/v1 " ,
64+ " https://blah.storage.supabase.co/storage/v1 " ,
65+ " accept new host without modification "
66+ ) ,
67+ (
68+ " https://blah.supabase.co.example.com/storage/v1 " ,
69+ " https://blah.supabase.co.example.com/storage/v1 " ,
70+ " not modify non-platform hosts "
71+ ) ,
72+ (
73+ " http://localhost:1234/storage/v1 " ,
74+ " http://localhost:1234/storage/v1 " ,
75+ " support local host with port without modification "
76+ ) ,
77+ ]
78+
79+ for (input, expect, description) in urlTestCases {
80+ XCTContext . runActivity ( named: " should \( description) if useNewHostname is true " ) { _ in
81+ let storage = SupabaseStorageClient (
82+ configuration: StorageClientConfiguration (
83+ url: URL ( string: input) !,
84+ headers: [ : ] ,
85+ useNewHostname: true
86+ )
87+ )
88+ XCTAssertEqual ( storage. configuration. url. absoluteString, expect)
89+ }
90+
91+ XCTContext . runActivity ( named: " should not modify host if useNewHostname is false " ) { _ in
92+ let storage = SupabaseStorageClient (
93+ configuration: StorageClientConfiguration (
94+ url: URL ( string: input) !,
95+ headers: [ : ] ,
96+ useNewHostname: false
97+ )
98+ )
99+ XCTAssertEqual ( storage. configuration. url. absoluteString, input)
100+ }
101+ }
102+ }
103+
50104 func testGetBucket( ) async throws {
51105 Mock (
52106 url: url. appendingPathComponent ( " bucket/bucket123 " ) ,
@@ -132,7 +186,8 @@ final class StorageBucketAPITests: XCTestCase {
132186 " created_at " : " 2024-01-01T00:00:00.000Z " ,
133187 " updated_at " : " 2024-01-01T00:00:00.000Z "
134188 }
135- """ . utf8)
189+ """ . utf8
190+ )
136191 ]
137192 )
138193 . snapshotRequest {
@@ -171,7 +226,8 @@ final class StorageBucketAPITests: XCTestCase {
171226 " created_at " : " 2024-01-01T00:00:00.000Z " ,
172227 " updated_at " : " 2024-01-01T00:00:00.000Z "
173228 }
174- """ . utf8)
229+ """ . utf8
230+ )
175231 ]
176232 )
177233 . snapshotRequest {
0 commit comments