Skip to content

Commit f069b21

Browse files
committed
use snapshot testing
1 parent 8bd9bf6 commit f069b21

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ let package = Package(
139139
name: "StorageTests",
140140
dependencies: [
141141
.product(name: "CustomDump", package: "swift-custom-dump"),
142+
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
142143
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
143144
"Storage",
144145
]

Sources/Storage/Helpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Helpers
2727
kUTTagClassFilenameExtension, pathExtension as CFString, nil
2828
)?.takeRetainedValue(),
2929
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?
30-
.takeRetainedValue()
30+
.takeRetainedValue()
3131
{
3232
return contentType as String
3333
}
@@ -43,7 +43,7 @@ import Helpers
4343
kUTTagClassFilenameExtension, pathExtension as CFString, nil
4444
)?.takeRetainedValue(),
4545
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?
46-
.takeRetainedValue()
46+
.takeRetainedValue()
4747
{
4848
return contentType as String
4949
}
@@ -62,7 +62,7 @@ import Helpers
6262
kUTTagClassFilenameExtension, pathExtension as CFString, nil
6363
)?.takeRetainedValue(),
6464
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?
65-
.takeRetainedValue()
65+
.takeRetainedValue()
6666
{
6767
return contentType as String
6868
}

Sources/Storage/StorageFileApi.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
668668
private func _removeEmptyFolders(_ path: String) -> String {
669669
let trimmedPath = path.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
670670
let cleanedPath = trimmedPath.replacingOccurrences(
671-
of: "/+", with: "/", options: .regularExpression)
671+
of: "/+", with: "/", options: .regularExpression
672+
)
672673
return cleanedPath
673674
}
674675
}

Tests/StorageTests/SupabaseStorageClient+Test.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ extension SupabaseStorageClient {
2121
"Authorization": "Bearer \(apiKey)",
2222
"Apikey": apiKey,
2323
],
24-
session: session
24+
session: session,
25+
logger: nil
2526
)
2627
)
2728
}
2829
}
2930

30-
struct ConsoleLogger: SupabaseLogger {
31-
func log(message: SupabaseLogMessage) {
32-
print(message.description)
33-
}
34-
}

Tests/StorageTests/SupabaseStorageTests.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CustomDump
22
import Foundation
3+
import InlineSnapshotTesting
34
@testable import Storage
45
import XCTest
56
import XCTestDynamicOverlay
@@ -17,7 +18,7 @@ final class SupabaseStorageTests: XCTestCase {
1718
upload: unimplemented("StorageHTTPSession.upload")
1819
)
1920

20-
func testGetPublicURL() async throws {
21+
func testGetPublicURL() throws {
2122
let sut = makeSUT()
2223

2324
let path = "README.md"
@@ -29,27 +30,30 @@ final class SupabaseStorageTests: XCTestCase {
2930
path: path,
3031
download: true
3132
)
32-
XCTAssertEqual(
33-
baseUrlWithDownload.absoluteString,
34-
"\(supabaseURL)/object/public/\(bucketId)/\(path)?download="
35-
)
33+
assertInlineSnapshot(of: baseUrlWithDownload, as: .description) {
34+
"""
35+
http://localhost:54321/storage/v1/object/public/tests/README.md?download=
36+
"""
37+
}
3638

3739
let baseUrlWithDownloadAndFileName = try sut.from(bucketId).getPublicURL(
3840
path: path, download: "test"
3941
)
40-
XCTAssertEqual(
41-
baseUrlWithDownloadAndFileName.absoluteString,
42-
"\(supabaseURL)/object/public/\(bucketId)/\(path)?download=test"
43-
)
42+
assertInlineSnapshot(of: baseUrlWithDownloadAndFileName, as: .description) {
43+
"""
44+
http://localhost:54321/storage/v1/object/public/tests/README.md?download=test
45+
"""
46+
}
4447

4548
let baseUrlWithAllOptions = try sut.from(bucketId).getPublicURL(
4649
path: path, download: "test",
4750
options: TransformOptions(width: 300, height: 300)
4851
)
49-
XCTAssertEqual(
50-
baseUrlWithAllOptions.absoluteString,
51-
"\(supabaseURL)/render/image/public/\(bucketId)/\(path)?download=test&width=300&height=300&quality=80"
52-
)
52+
assertInlineSnapshot(of: baseUrlWithAllOptions, as: .description) {
53+
"""
54+
http://localhost:54321/storage/v1/render/image/public/tests/README.md?download=test&width=300&height=300&quality=80
55+
"""
56+
}
5357
}
5458

5559
func testCreateSignedURLs() async throws {
@@ -80,13 +84,11 @@ final class SupabaseStorageTests: XCTestCase {
8084
expiresIn: 60
8185
)
8286

83-
expectNoDifference(
84-
urls.map(\.absoluteString),
85-
[
86-
"\(supabaseURL.absoluteString)/sign/file1.txt?token=abc.def.ghi",
87-
"\(supabaseURL.absoluteString)/sign/file2.txt?token=abc.def.ghi",
88-
]
89-
)
87+
assertInlineSnapshot(of: urls, as: .description) {
88+
"""
89+
[http://localhost:54321/storage/v1/sign/file1.txt?token=abc.def.ghi, http://localhost:54321/storage/v1/sign/file2.txt?token=abc.def.ghi]
90+
"""
91+
}
9092
}
9193

9294
private func makeSUT() -> SupabaseStorageClient {

0 commit comments

Comments
 (0)