@@ -3,12 +3,12 @@ import Mocker
3
3
import TestHelpers
4
4
import XCTest
5
5
6
+ @testable import Storage
7
+
6
8
#if canImport(FoundationNetworking)
7
9
import FoundationNetworking
8
10
#endif
9
11
10
- @testable import Storage
11
-
12
12
final class StorageBucketAPITests : XCTestCase {
13
13
let url = URL ( string: " http://localhost:54321/storage/v1 " ) !
14
14
var storage : SupabaseStorageClient !
@@ -47,6 +47,60 @@ final class StorageBucketAPITests: XCTestCase {
47
47
Mocker . removeAll ( )
48
48
}
49
49
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
+
50
104
func testGetBucket( ) async throws {
51
105
Mock (
52
106
url: url. appendingPathComponent ( " bucket/bucket123 " ) ,
@@ -132,7 +186,8 @@ final class StorageBucketAPITests: XCTestCase {
132
186
" created_at " : " 2024-01-01T00:00:00.000Z " ,
133
187
" updated_at " : " 2024-01-01T00:00:00.000Z "
134
188
}
135
- """ . utf8)
189
+ """ . utf8
190
+ )
136
191
]
137
192
)
138
193
. snapshotRequest {
@@ -171,7 +226,8 @@ final class StorageBucketAPITests: XCTestCase {
171
226
" created_at " : " 2024-01-01T00:00:00.000Z " ,
172
227
" updated_at " : " 2024-01-01T00:00:00.000Z "
173
228
}
174
- """ . utf8)
229
+ """ . utf8
230
+ )
175
231
]
176
232
)
177
233
. snapshotRequest {
0 commit comments