Skip to content

Commit 1e04018

Browse files
authored
[Infra] Remove HeartbeatLoggingTestUtils.podspec (#11370)
* [Infra] Remove HeartbeatLoggingTestUtils.podspec * Review
1 parent c559a68 commit 1e04018

20 files changed

+276
-357
lines changed

FirebaseAppCheck.podspec

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,24 @@ Pod::Spec.new do |s|
5454
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"'
5555
}
5656

57-
# Using environment variable because of the dependency on the unpublished
58-
# HeartbeatLoggingTestUtils.
59-
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
60-
s.test_spec 'unit' do |unit_tests|
61-
unit_tests.platforms = {
62-
:ios => ios_deployment_target,
63-
:osx => osx_deployment_target,
64-
:tvos => tvos_deployment_target
65-
}
66-
unit_tests.source_files = [
67-
base_dir + 'Tests/Unit/**/*.[mh]',
68-
base_dir + 'Tests/Utils/**/*.[mh]',
69-
'SharedTestUtilities/AppCheckFake/*',
70-
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
71-
'SharedTestUtilities/Date/*',
72-
'SharedTestUtilities/URLSession/*',
73-
]
74-
75-
unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
76-
unit_tests.dependency 'OCMock'
77-
unit_tests.dependency 'HeartbeatLoggingTestUtils'
78-
unit_tests.requires_app_host = true
79-
end
57+
s.test_spec 'unit' do |unit_tests|
58+
unit_tests.platforms = {
59+
:ios => ios_deployment_target,
60+
:osx => osx_deployment_target,
61+
:tvos => tvos_deployment_target
62+
}
63+
unit_tests.source_files = [
64+
base_dir + 'Tests/Unit/**/*.[mh]',
65+
base_dir + 'Tests/Utils/**/*.[mh]',
66+
'SharedTestUtilities/AppCheckFake/*',
67+
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
68+
'SharedTestUtilities/Date/*',
69+
'SharedTestUtilities/URLSession/*',
70+
]
71+
72+
unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
73+
unit_tests.dependency 'OCMock'
74+
unit_tests.requires_app_host = true
8075
end
8176

8277
s.test_spec 'integration' do |integration_tests|

FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckAPIServiceTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#import <OCMock/OCMock.h>
2020
#import "FBLPromise+Testing.h"
2121

22-
@import HeartbeatLoggingTestUtils;
22+
@import FirebaseCoreInternal;
2323

2424
#import <GoogleUtilities/GULURLSessionDataResponse.h>
2525
#import <GoogleUtilities/NSURLSession+GULPromises.h>

FirebaseAuth.podspec

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,57 +58,52 @@ supports email and password accounts, as well as several 3rd party authenticatio
5858
s.dependency 'GoogleUtilities/Environment', '~> 7.8'
5959
s.dependency 'GTMSessionFetcher/Core', '>= 2.1', '< 4.0'
6060

61-
# Using environment variable because of the dependency on the unpublished
62-
# HeartbeatLoggingTestUtils.
63-
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
64-
s.test_spec 'unit' do |unit_tests|
65-
unit_tests.scheme = { :code_coverage => true }
66-
# Unit tests can't run on watchOS.
67-
unit_tests.platforms = {
68-
:ios => ios_deployment_target,
69-
:osx => osx_deployment_target,
70-
:tvos => tvos_deployment_target
71-
}
72-
unit_tests.source_files = 'FirebaseAuth/Tests/Unit/*.[mh]'
73-
unit_tests.osx.exclude_files = [
74-
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
75-
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenTests.m',
76-
'FirebaseAuth/Tests/Unit/FIRAuthAppCredentialManagerTests.m',
77-
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
78-
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
79-
'FirebaseAuth/Tests/Unit/FIREmailLink*',
80-
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
81-
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
82-
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
83-
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
84-
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
85-
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
86-
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
87-
]
88-
unit_tests.tvos.exclude_files = [
89-
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
90-
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
91-
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
92-
'FirebaseAuth/Tests/Unit/FIREmailLink*',
93-
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
94-
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
95-
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
96-
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
97-
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
98-
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
99-
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
100-
]
101-
# app_host is needed for tests with keychain
102-
unit_tests.requires_app_host = true
103-
unit_tests.dependency 'OCMock'
104-
unit_tests.dependency 'HeartbeatLoggingTestUtils'
61+
s.test_spec 'unit' do |unit_tests|
62+
unit_tests.scheme = { :code_coverage => true }
63+
# Unit tests can't run on watchOS.
64+
unit_tests.platforms = {
65+
:ios => ios_deployment_target,
66+
:osx => osx_deployment_target,
67+
:tvos => tvos_deployment_target
68+
}
69+
unit_tests.source_files = 'FirebaseAuth/Tests/Unit/*.[mh]'
70+
unit_tests.osx.exclude_files = [
71+
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
72+
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenTests.m',
73+
'FirebaseAuth/Tests/Unit/FIRAuthAppCredentialManagerTests.m',
74+
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
75+
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
76+
'FirebaseAuth/Tests/Unit/FIREmailLink*',
77+
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
78+
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
79+
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
80+
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
81+
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
82+
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
83+
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
84+
]
85+
unit_tests.tvos.exclude_files = [
86+
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
87+
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
88+
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
89+
'FirebaseAuth/Tests/Unit/FIREmailLink*',
90+
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
91+
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
92+
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
93+
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
94+
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
95+
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
96+
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
97+
]
98+
# app_host is needed for tests with keychain
99+
unit_tests.requires_app_host = true
100+
unit_tests.dependency 'OCMock'
105101

106-
# This pre-processor directive is used to selectively disable keychain
107-
# related code that blocks unit testing on macOS.
108-
s.osx.pod_target_xcconfig = {
109-
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIREBASE_AUTH_MACOS_TESTING=1'
110-
}
102+
# This pre-processor directive is used to selectively disable keychain
103+
# related code that blocks unit testing on macOS.
104+
s.osx.pod_target_xcconfig = {
105+
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIREBASE_AUTH_MACOS_TESTING=1'
106+
}
111107

112-
end
113108
end
114109
end

FirebaseAuth/Tests/Sample/Podfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ target 'AuthSample' do
2020

2121
target 'Auth_ApiTests' do
2222
inherit! :search_paths
23-
# `HeartbeatLoggingTestUtils` is unpublished.
24-
pod 'HeartbeatLoggingTestUtils', :path => '../../../'
2523
end
2624

2725
target 'SwiftApiTests' do

FirebaseAuth/Tests/Unit/FIRAuthBackendRPCImplementationTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19-
@import HeartbeatLoggingTestUtils;
19+
@import FirebaseCoreInternal;
2020

2121
#import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
2222
#import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"

FirebaseCore.podspec

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,21 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
5858
'OTHER_CFLAGS' => '-fno-autolink'
5959
}
6060

61-
# Using environment variable because of the dependency on the unpublished
62-
# HeartbeatLoggingTestUtils.
63-
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
64-
s.test_spec 'unit' do |unit_tests|
65-
unit_tests.scheme = { :code_coverage => true }
66-
unit_tests.platforms = {
67-
:ios => ios_deployment_target,
68-
:osx => '10.15',
69-
:tvos => tvos_deployment_target
70-
}
71-
unit_tests.source_files = [
72-
'FirebaseCore/Tests/Unit/**/*.[mh]',
73-
'SharedTestUtilities/FIROptionsMock.[mh]',
74-
]
75-
76-
unit_tests.requires_app_host = true
77-
unit_tests.dependency 'OCMock'
78-
unit_tests.dependency 'HeartbeatLoggingTestUtils'
79-
unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
80-
end
61+
s.test_spec 'unit' do |unit_tests|
62+
unit_tests.scheme = { :code_coverage => true }
63+
unit_tests.platforms = {
64+
:ios => ios_deployment_target,
65+
:osx => '10.15',
66+
:tvos => tvos_deployment_target
67+
}
68+
unit_tests.source_files = [
69+
'FirebaseCore/Tests/Unit/**/*.[mh]',
70+
'SharedTestUtilities/FIROptionsMock.[mh]',
71+
]
72+
73+
unit_tests.requires_app_host = true
74+
unit_tests.dependency 'OCMock'
75+
unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
8176
end
8277

8378
s.test_spec 'swift-unit' do |swift_unit_tests|
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#if DEBUG
16+
17+
import Foundation
18+
19+
/// A utility class intended to be used only in testing contexts.
20+
@objc(FIRHeartbeatLoggingTestUtils)
21+
@objcMembers
22+
public class HeartbeatLoggingTestUtils: NSObject {
23+
/// This should mirror the `Constants` enum in the `HeartbeatLogging` module.
24+
/// See `HeartbeatLogging/Sources/StorageFactory.swift`.
25+
public enum Constants {
26+
/// The name of the file system directory where heartbeat data is stored.
27+
public static let heartbeatFileStorageDirectoryPath = "google-heartbeat-storage"
28+
/// The name of the user defaults suite where heartbeat data is stored.
29+
public static let heartbeatUserDefaultsSuiteName = "com.google.heartbeat.storage"
30+
}
31+
32+
public static var dateFormatter: DateFormatter {
33+
HeartbeatsPayload.dateFormatter
34+
}
35+
36+
public static var emptyHeartbeatsPayload: _ObjC_HeartbeatsPayload {
37+
let literalData = """
38+
{
39+
"version": 2,
40+
"heartbeats": []
41+
}
42+
"""
43+
.data(using: .utf8)!
44+
45+
let decoder = JSONDecoder()
46+
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)
47+
48+
let heartbeatsPayload = try! decoder.decode(HeartbeatsPayload.self, from: literalData)
49+
return _ObjC_HeartbeatsPayload(heartbeatsPayload)
50+
}
51+
52+
public static var nonEmptyHeartbeatsPayload: _ObjC_HeartbeatsPayload {
53+
let literalData = """
54+
{
55+
"version": 2,
56+
"heartbeats": [
57+
{
58+
"agent": "dummy_agent_1",
59+
"dates": ["2021-11-01", "2021-11-02"]
60+
},
61+
{
62+
"agent": "dummy_agent_2",
63+
"dates": ["2021-11-03"]
64+
}
65+
]
66+
}
67+
"""
68+
.data(using: .utf8)!
69+
70+
let decoder = JSONDecoder()
71+
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)
72+
73+
let heartbeatsPayload = try! decoder.decode(HeartbeatsPayload.self, from: literalData)
74+
return _ObjC_HeartbeatsPayload(heartbeatsPayload)
75+
}
76+
77+
@objc(assertEncodedPayloadString:isEqualToLiteralString:withError:)
78+
public static func assertEqualPayloadStrings(_ encoded: String, _ literal: String) throws {
79+
var encodedData = Data(base64URLEncoded: encoded)!
80+
if encodedData.count > 0 {
81+
encodedData = try! encodedData.unzipped()
82+
}
83+
84+
let literalData = literal.data(using: .utf8)!
85+
86+
let decoder = JSONDecoder()
87+
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)
88+
89+
let payloadFromEncoded = try? decoder.decode(HeartbeatsPayload.self, from: encodedData)
90+
91+
let payloadFromLiteral = try? decoder.decode(HeartbeatsPayload.self, from: literalData)
92+
93+
let encoder = JSONEncoder()
94+
encoder.dateEncodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)
95+
encoder.outputFormatting = .prettyPrinted
96+
97+
let payloadDataFromEncoded = try! encoder.encode(payloadFromEncoded)
98+
let payloadDataFromLiteral = try! encoder.encode(payloadFromLiteral)
99+
100+
assert(
101+
payloadFromEncoded == payloadFromLiteral,
102+
"""
103+
Mismatched payloads!
104+
105+
Payload 1:
106+
\(String(data: payloadDataFromEncoded, encoding: .utf8) ?? "")
107+
108+
Payload 2:
109+
\(String(data: payloadDataFromLiteral, encoding: .utf8) ?? "")
110+
111+
"""
112+
)
113+
}
114+
115+
/// Removes all underlying storage containers used by the module.
116+
/// - Throws: An error if the storage container could not be removed.
117+
public static func removeUnderlyingHeartbeatStorageContainers() throws {
118+
#if os(tvOS)
119+
UserDefaults().removePersistentDomain(forName: Constants.heartbeatUserDefaultsSuiteName)
120+
#else
121+
122+
let applicationSupportDirectory = FileManager.default
123+
.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
124+
125+
let heartbeatsDirectoryURL = applicationSupportDirectory
126+
.appendingPathComponent(
127+
Constants.heartbeatFileStorageDirectoryPath, isDirectory: true
128+
)
129+
do {
130+
try FileManager.default.removeItem(at: heartbeatsDirectoryURL)
131+
} catch CocoaError.fileNoSuchFile {
132+
// Do nothing.
133+
} catch {
134+
throw error
135+
}
136+
#endif // os(tvOS)
137+
}
138+
}
139+
140+
#endif // ENABLE_FIREBASE_CORE_INTERNAL_TESTING_UTILS

FirebaseCore/Internal/Tests/Common/Assertions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import XCTest
1616
@testable import FirebaseCoreInternal
17-
import HeartbeatLoggingTestUtils
1817

1918
// MARK: - Assertions
2019

FirebaseCore/Internal/Tests/Integration/HeartbeatLoggingIntegrationTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import XCTest
1616
@testable import FirebaseCoreInternal
17-
import HeartbeatLoggingTestUtils
1817

1918
class HeartbeatLoggingIntegrationTests: XCTestCase {
2019
// 2021-11-01 @ 00:00:00 (EST)

FirebaseCore/Internal/Tests/Unit/HeartbeatControllerTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import XCTest
1616
@testable import FirebaseCoreInternal
17-
import HeartbeatLoggingTestUtils
1817

1918
class HeartbeatControllerTests: XCTestCase {
2019
// 2021-11-01 @ 00:00:00 (EST)

0 commit comments

Comments
 (0)