@@ -19,29 +19,9 @@ import XCTest
1919
2020@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
2121class StorageDeleteTests : StorageTestHelpers {
22- var fetcherService : GTMSessionFetcherService ?
23- var dispatchQueue : DispatchQueue ?
24-
25- override func setUp( ) {
26- super. setUp ( )
27- fetcherService = GTMSessionFetcherService ( )
28- fetcherService? . authorizer = StorageTokenAuthorizer (
29- googleAppID: " dummyAppID " ,
30- authProvider: nil ,
31- appCheck: nil
32- )
33- dispatchQueue = DispatchQueue ( label: " Test dispatch queue " )
34- }
35-
36- override func tearDown( ) {
37- fetcherService = nil
38- super. tearDown ( )
39- }
40-
41- func testFetcherConfiguration( ) {
42- let expectation = self . expectation ( description: #function)
43- fetcherService!. testBlock = { ( fetcher: GTMSessionFetcher!,
44- response: GTMSessionFetcherTestResponse) in
22+ func testFetcherConfiguration( ) async {
23+ let testBlock = { ( fetcher: GTMSessionFetcher!,
24+ response: GTMSessionFetcherTestResponse) in
4525 XCTAssertEqual ( fetcher. request? . url, self . objectURL ( ) )
4626 XCTAssertEqual ( fetcher. request? . httpMethod, " DELETE " )
4727 let httpResponse = HTTPURLResponse (
@@ -52,67 +32,46 @@ class StorageDeleteTests: StorageTestHelpers {
5232 )
5333 response ( httpResponse, nil , nil )
5434 }
35+ await StorageFetcherService . shared. updateTestBlock ( testBlock)
5536 let path = objectPath ( )
5637 let ref = StorageReference ( storage: storage ( ) , path: path)
57- StorageDeleteTask . deleteTask (
58- reference: ref,
59- queue: dispatchQueue!. self
60- ) { _, error in
61- expectation. fulfill ( )
38+ do {
39+ let _ = try await ref. delete ( )
40+ } catch {
41+ // All testing is in test block.
6242 }
63- waitForExpectation ( test: self )
6443 }
6544
66- func testSuccessfulFetch( ) {
67- let expectation = self . expectation ( description: #function)
68- fetcherService!. testBlock = { ( fetcher: GTMSessionFetcher!,
69- response: GTMSessionFetcherTestResponse) in
70- XCTAssertEqual ( fetcher. request? . url, self . objectURL ( ) )
71- XCTAssertEqual ( fetcher. request? . httpMethod, " DELETE " )
72- let httpResponse = HTTPURLResponse (
73- url: ( fetcher. request? . url) !,
74- statusCode: 200 ,
75- httpVersion: " HTTP/1.1 " ,
76- headerFields: nil
77- )
78- response ( httpResponse, nil , nil )
79- }
45+ func testSuccessfulFetch( ) async {
46+ await StorageFetcherService . shared. updateTestBlock ( successBlock ( ) )
8047 let path = objectPath ( )
8148 let ref = StorageReference ( storage: storage ( ) , path: path)
82- StorageDeleteTask . deleteTask (
83- reference: ref,
84- queue: dispatchQueue!. self
85- ) { _, error in
86- expectation. fulfill ( )
49+ do {
50+ let _ = try await ref. delete ( )
51+ } catch {
52+ // All testing is in test block.
8753 }
88- waitForExpectation ( test: self )
8954 }
9055
91- func testSuccessfulFetchWithEmulator( ) {
92- let expectation = self . expectation ( description: #function)
56+ func testSuccessfulFetchWithEmulator( ) async {
9357 let storage = self . storage ( )
9458 storage. useEmulator ( withHost: " localhost " , port: 8080 )
95- fetcherService? . allowLocalhostRequest = true
96-
97- fetcherService!
98- . testBlock = successBlock (
99- withURL: URL ( string: " http://localhost:8080/v0/b/bucket/o/object " ) !
100- )
101-
59+ let testBlock = successBlock (
60+ withURL: URL ( string: " http://localhost:8080/v0/b/bucket/o/object " ) !
61+ )
62+ await StorageFetcherService . shared. updateTestBlock ( successBlock ( ) )
10263 let path = objectPath ( )
10364 let ref = StorageReference ( storage: storage, path: path)
104- StorageDeleteTask . deleteTask (
105- reference: ref,
106- queue: dispatchQueue!. self
107- ) { _, error in
108- expectation. fulfill ( )
65+ do {
66+ let _ = try await ref. delete ( )
67+ } catch {
68+ // All testing is in test block.
10969 }
110- waitForExpectation ( test: self )
11170 }
11271
11372 func testUnsuccessfulFetchUnauthenticated( ) async {
11473 let storage = storage ( )
115- await storage . fetcherService . updateTestBlock ( unauthenticatedBlock ( ) )
74+ await StorageFetcherService . shared . updateTestBlock ( unauthenticatedBlock ( ) )
11675 let path = objectPath ( )
11776 let ref = StorageReference ( storage: storage, path: path)
11877 do {
@@ -124,7 +83,7 @@ class StorageDeleteTests: StorageTestHelpers {
12483
12584 func testUnsuccessfulFetchUnauthorized( ) async {
12685 let storage = storage ( )
127- await storage . fetcherService . updateTestBlock ( unauthorizedBlock ( ) )
86+ await StorageFetcherService . shared . updateTestBlock ( unauthorizedBlock ( ) )
12887 let path = objectPath ( )
12988 let ref = StorageReference ( storage: storage, path: path)
13089 do {
@@ -136,7 +95,7 @@ class StorageDeleteTests: StorageTestHelpers {
13695
13796 func testUnsuccessfulFetchObjectDoesntExist( ) async {
13897 let storage = storage ( )
139- await storage . fetcherService . updateTestBlock ( notFoundBlock ( ) )
98+ await StorageFetcherService . shared . updateTestBlock ( notFoundBlock ( ) )
14099 let path = objectPath ( )
141100 let ref = StorageReference ( storage: storage, path: path)
142101 do {
0 commit comments