File tree 5 files changed +93
-14
lines changed
5 files changed +93
-14
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ let package = Package(
181
181
name: " SupabaseTests " ,
182
182
dependencies: [
183
183
. product( name: " CustomDump " , package : " swift-custom-dump " ) ,
184
+ . product( name: " InlineSnapshotTesting " , package : " swift-snapshot-testing " ) ,
184
185
" Supabase " ,
185
186
]
186
187
) ,
Original file line number Diff line number Diff line change
1
+ import Foundation
1
2
import XCTestDynamicOverlay
2
3
3
4
private let _version = " 2.26.0 " // {x-release-please-version}
@@ -7,3 +8,49 @@ private let _version = "2.26.0" // {x-release-please-version}
7
8
#else
8
9
package let version = _version
9
10
#endif
11
+
12
+ private let _platform : String ? = {
13
+ #if os(macOS)
14
+ return " macOS "
15
+ #elseif os(iOS)
16
+ return " iOS "
17
+ #elseif os(tvOS)
18
+ return " tvOS "
19
+ #elseif os(watchOS)
20
+ return " watchOS "
21
+ #elseif os(Android)
22
+ return " Android "
23
+ #elseif os(Linux)
24
+ return " Linux "
25
+ #elseif os(Windows)
26
+ return " Windows "
27
+ #else
28
+ return nil
29
+ #endif
30
+ } ( )
31
+
32
+ private let _platformVersion : String ? = {
33
+ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Windows)
34
+ ProcessInfo . processInfo. operatingSystemVersionString
35
+ #elseif os(Linux) || os(Android)
36
+ if let version = try ? String ( contentsOfFile: " /proc/version " ) {
37
+ version. trimmingCharacters ( in: . whitespacesAndNewlines)
38
+ } else {
39
+ nil
40
+ }
41
+ #else
42
+ nil
43
+ #endif
44
+ } ( )
45
+
46
+ #if DEBUG
47
+ package let platform = isTesting ? " macOS " : _platform
48
+ #else
49
+ package let platform = _platform
50
+ #endif
51
+
52
+ #if DEBUG
53
+ package let platformVersion = isTesting ? " 0.0.0 " : _platformVersion
54
+ #else
55
+ package let platformVersion = _platformVersion
56
+ #endif
Original file line number Diff line number Diff line change
1
+ //
2
+ // Constants.swift
3
+ // Supabase
4
+ //
5
+ // Created by Guilherme Souza on 06/03/25.
6
+ //
7
+
8
+ import Foundation
9
+ import Helpers
10
+
11
+ let defaultHeaders : [ String : String ] = {
12
+ var headers = [
13
+ " X-Client-Info " : " supabase-swift/ \( version) "
14
+ ]
15
+
16
+ if let platform {
17
+ headers [ " X-Supabase-Client-Platform " ] = platform
18
+ }
19
+
20
+ if let platformVersion {
21
+ headers [ " X-Supabase-Client-Platform-Version " ] = platformVersion
22
+ }
23
+
24
+ return headers
25
+ } ( )
Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ public typealias SupabaseLogger = Helpers.SupabaseLogger
17
17
public typealias SupabaseLogLevel = Helpers . SupabaseLogLevel
18
18
public typealias SupabaseLogMessage = Helpers . SupabaseLogMessage
19
19
20
- let version = Helpers . version
21
-
22
20
/// Supabase Client.
23
21
public final class SupabaseClient : Sendable {
24
22
let options : SupabaseClientOptions
@@ -163,12 +161,16 @@ public final class SupabaseClient: Sendable {
163
161
databaseURL = supabaseURL. appendingPathComponent ( " /rest/v1 " )
164
162
functionsURL = supabaseURL. appendingPathComponent ( " /functions/v1 " )
165
163
166
- _headers = HTTPFields ( [
167
- " X-Client-Info " : " supabase-swift/ \( version) " ,
168
- " Authorization " : " Bearer \( supabaseKey) " ,
169
- " Apikey " : supabaseKey,
170
- ] )
171
- . merging ( with: HTTPFields ( options. global. headers) )
164
+ _headers = HTTPFields ( defaultHeaders)
165
+ . merging (
166
+ with: HTTPFields (
167
+ [
168
+ " Authorization " : " Bearer \( supabaseKey) " ,
169
+ " Apikey " : supabaseKey,
170
+ ]
171
+ )
172
+ )
173
+ . merging ( with: HTTPFields ( options. global. headers) )
172
174
173
175
// default storage key uses the supabase project ref as a namespace
174
176
let defaultStorageKey = " sb- \( supabaseURL. host!. split ( separator: " . " ) [ 0 ] ) -auth-token "
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import IssueReporting
5
5
@testable import Realtime
6
6
@testable import Supabase
7
7
import XCTest
8
+ import InlineSnapshotTesting
9
+ import SnapshotTestingCustomDump
8
10
9
11
final class AuthLocalStorageMock : AuthLocalStorage {
10
12
func store( key _: String , value _: Data ) throws { }
@@ -61,16 +63,18 @@ final class SupabaseClientTests: XCTestCase {
61
63
" https://project-ref.supabase.co/functions/v1 "
62
64
)
63
65
64
- XCTAssertEqual (
65
- client . headers ,
66
+ assertInlineSnapshot ( of : client . headers , as : . customDump ) {
67
+ """
66
68
[
67
- " X-Client-Info " : " supabase-swift/ \( Supabase . version) " ,
68
69
" Apikey " : " ANON_KEY " ,
69
- " header_field " : " header_value " ,
70
70
" Authorization " : " Bearer ANON_KEY " ,
71
+ " X-Client-Info " : " supabase-swift/0.0.0 " ,
72
+ " X-Supabase-Client-Platform " : " macOS " ,
73
+ " X-Supabase-Client-Platform-Version " : " 0.0.0 " ,
74
+ " header_field " : " header_value "
71
75
]
72
- )
73
- expectNoDifference ( client . _headers . dictionary , client . headers )
76
+ """
77
+ }
74
78
75
79
XCTAssertEqual ( client. functions. region, " ap-northeast-1 " )
76
80
You can’t perform that action at this time.
0 commit comments