Skip to content

Commit

Permalink
[Infra] Remove HeartbeatLoggingTestUtils.podspec (#11370)
Browse files Browse the repository at this point in the history
* [Infra] Remove HeartbeatLoggingTestUtils.podspec

* Review
  • Loading branch information
ncooke3 authored Jun 1, 2023
1 parent c559a68 commit 1e04018
Show file tree
Hide file tree
Showing 20 changed files with 276 additions and 357 deletions.
41 changes: 18 additions & 23 deletions FirebaseAppCheck.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,24 @@ Pod::Spec.new do |s|
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"'
}

# Using environment variable because of the dependency on the unpublished
# HeartbeatLoggingTestUtils.
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
s.test_spec 'unit' do |unit_tests|
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => osx_deployment_target,
:tvos => tvos_deployment_target
}
unit_tests.source_files = [
base_dir + 'Tests/Unit/**/*.[mh]',
base_dir + 'Tests/Utils/**/*.[mh]',
'SharedTestUtilities/AppCheckFake/*',
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
'SharedTestUtilities/Date/*',
'SharedTestUtilities/URLSession/*',
]

unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
unit_tests.dependency 'OCMock'
unit_tests.dependency 'HeartbeatLoggingTestUtils'
unit_tests.requires_app_host = true
end
s.test_spec 'unit' do |unit_tests|
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => osx_deployment_target,
:tvos => tvos_deployment_target
}
unit_tests.source_files = [
base_dir + 'Tests/Unit/**/*.[mh]',
base_dir + 'Tests/Utils/**/*.[mh]',
'SharedTestUtilities/AppCheckFake/*',
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
'SharedTestUtilities/Date/*',
'SharedTestUtilities/URLSession/*',
]

unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
unit_tests.dependency 'OCMock'
unit_tests.requires_app_host = true
end

s.test_spec 'integration' do |integration_tests|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import <OCMock/OCMock.h>
#import "FBLPromise+Testing.h"

@import HeartbeatLoggingTestUtils;
@import FirebaseCoreInternal;

#import <GoogleUtilities/GULURLSessionDataResponse.h>
#import <GoogleUtilities/NSURLSession+GULPromises.h>
Expand Down
95 changes: 45 additions & 50 deletions FirebaseAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -58,57 +58,52 @@ supports email and password accounts, as well as several 3rd party authenticatio
s.dependency 'GoogleUtilities/Environment', '~> 7.8'
s.dependency 'GTMSessionFetcher/Core', '>= 2.1', '< 4.0'

# Using environment variable because of the dependency on the unpublished
# HeartbeatLoggingTestUtils.
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
s.test_spec 'unit' do |unit_tests|
unit_tests.scheme = { :code_coverage => true }
# Unit tests can't run on watchOS.
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => osx_deployment_target,
:tvos => tvos_deployment_target
}
unit_tests.source_files = 'FirebaseAuth/Tests/Unit/*.[mh]'
unit_tests.osx.exclude_files = [
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthAppCredentialManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
'FirebaseAuth/Tests/Unit/FIREmailLink*',
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
]
unit_tests.tvos.exclude_files = [
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
'FirebaseAuth/Tests/Unit/FIREmailLink*',
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
]
# app_host is needed for tests with keychain
unit_tests.requires_app_host = true
unit_tests.dependency 'OCMock'
unit_tests.dependency 'HeartbeatLoggingTestUtils'
s.test_spec 'unit' do |unit_tests|
unit_tests.scheme = { :code_coverage => true }
# Unit tests can't run on watchOS.
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => osx_deployment_target,
:tvos => tvos_deployment_target
}
unit_tests.source_files = 'FirebaseAuth/Tests/Unit/*.[mh]'
unit_tests.osx.exclude_files = [
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthAppCredentialManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
'FirebaseAuth/Tests/Unit/FIREmailLink*',
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
]
unit_tests.tvos.exclude_files = [
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthNotificationManagerTests.m',
'FirebaseAuth/Tests/Unit/FIRAuthURLPresenterTests.m',
'FirebaseAuth/Tests/Unit/FIREmailLink*',
'FirebaseAuth/Tests/Unit/FIRPhoneAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRSendVerificationCode*',
'FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m',
'FirebaseAuth/Tests/Unit/FIRVerifyClient*',
'FirebaseAuth/Tests/Unit/FIRVerifyPhoneNumber*',
'FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m',
'FirebaseAuth/Tests/Unit/FIRMultiFactorResolverTests.m',
]
# app_host is needed for tests with keychain
unit_tests.requires_app_host = true
unit_tests.dependency 'OCMock'

# This pre-processor directive is used to selectively disable keychain
# related code that blocks unit testing on macOS.
s.osx.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIREBASE_AUTH_MACOS_TESTING=1'
}
# This pre-processor directive is used to selectively disable keychain
# related code that blocks unit testing on macOS.
s.osx.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIREBASE_AUTH_MACOS_TESTING=1'
}

end
end
end
2 changes: 0 additions & 2 deletions FirebaseAuth/Tests/Sample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ target 'AuthSample' do

target 'Auth_ApiTests' do
inherit! :search_paths
# `HeartbeatLoggingTestUtils` is unpublished.
pod 'HeartbeatLoggingTestUtils', :path => '../../../'
end

target 'SwiftApiTests' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#import <XCTest/XCTest.h>

@import HeartbeatLoggingTestUtils;
@import FirebaseCoreInternal;

#import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
#import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"
Expand Down
35 changes: 15 additions & 20 deletions FirebaseCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,21 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
'OTHER_CFLAGS' => '-fno-autolink'
}

# Using environment variable because of the dependency on the unpublished
# HeartbeatLoggingTestUtils.
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
s.test_spec 'unit' do |unit_tests|
unit_tests.scheme = { :code_coverage => true }
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => '10.15',
:tvos => tvos_deployment_target
}
unit_tests.source_files = [
'FirebaseCore/Tests/Unit/**/*.[mh]',
'SharedTestUtilities/FIROptionsMock.[mh]',
]

unit_tests.requires_app_host = true
unit_tests.dependency 'OCMock'
unit_tests.dependency 'HeartbeatLoggingTestUtils'
unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
end
s.test_spec 'unit' do |unit_tests|
unit_tests.scheme = { :code_coverage => true }
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => '10.15',
:tvos => tvos_deployment_target
}
unit_tests.source_files = [
'FirebaseCore/Tests/Unit/**/*.[mh]',
'SharedTestUtilities/FIROptionsMock.[mh]',
]

unit_tests.requires_app_host = true
unit_tests.dependency 'OCMock'
unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
end

s.test_spec 'swift-unit' do |swift_unit_tests|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if DEBUG

import Foundation

/// A utility class intended to be used only in testing contexts.
@objc(FIRHeartbeatLoggingTestUtils)
@objcMembers
public class HeartbeatLoggingTestUtils: NSObject {
/// This should mirror the `Constants` enum in the `HeartbeatLogging` module.
/// See `HeartbeatLogging/Sources/StorageFactory.swift`.
public enum Constants {
/// The name of the file system directory where heartbeat data is stored.
public static let heartbeatFileStorageDirectoryPath = "google-heartbeat-storage"
/// The name of the user defaults suite where heartbeat data is stored.
public static let heartbeatUserDefaultsSuiteName = "com.google.heartbeat.storage"
}

public static var dateFormatter: DateFormatter {
HeartbeatsPayload.dateFormatter
}

public static var emptyHeartbeatsPayload: _ObjC_HeartbeatsPayload {
let literalData = """
{
"version": 2,
"heartbeats": []
}
"""
.data(using: .utf8)!

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)

let heartbeatsPayload = try! decoder.decode(HeartbeatsPayload.self, from: literalData)
return _ObjC_HeartbeatsPayload(heartbeatsPayload)
}

public static var nonEmptyHeartbeatsPayload: _ObjC_HeartbeatsPayload {
let literalData = """
{
"version": 2,
"heartbeats": [
{
"agent": "dummy_agent_1",
"dates": ["2021-11-01", "2021-11-02"]
},
{
"agent": "dummy_agent_2",
"dates": ["2021-11-03"]
}
]
}
"""
.data(using: .utf8)!

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)

let heartbeatsPayload = try! decoder.decode(HeartbeatsPayload.self, from: literalData)
return _ObjC_HeartbeatsPayload(heartbeatsPayload)
}

@objc(assertEncodedPayloadString:isEqualToLiteralString:withError:)
public static func assertEqualPayloadStrings(_ encoded: String, _ literal: String) throws {
var encodedData = Data(base64URLEncoded: encoded)!
if encodedData.count > 0 {
encodedData = try! encodedData.unzipped()
}

let literalData = literal.data(using: .utf8)!

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)

let payloadFromEncoded = try? decoder.decode(HeartbeatsPayload.self, from: encodedData)

let payloadFromLiteral = try? decoder.decode(HeartbeatsPayload.self, from: literalData)

let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .formatted(HeartbeatsPayload.dateFormatter)
encoder.outputFormatting = .prettyPrinted

let payloadDataFromEncoded = try! encoder.encode(payloadFromEncoded)
let payloadDataFromLiteral = try! encoder.encode(payloadFromLiteral)

assert(
payloadFromEncoded == payloadFromLiteral,
"""
Mismatched payloads!
Payload 1:
\(String(data: payloadDataFromEncoded, encoding: .utf8) ?? "")
Payload 2:
\(String(data: payloadDataFromLiteral, encoding: .utf8) ?? "")
"""
)
}

/// Removes all underlying storage containers used by the module.
/// - Throws: An error if the storage container could not be removed.
public static func removeUnderlyingHeartbeatStorageContainers() throws {
#if os(tvOS)
UserDefaults().removePersistentDomain(forName: Constants.heartbeatUserDefaultsSuiteName)
#else

let applicationSupportDirectory = FileManager.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!

let heartbeatsDirectoryURL = applicationSupportDirectory
.appendingPathComponent(
Constants.heartbeatFileStorageDirectoryPath, isDirectory: true
)
do {
try FileManager.default.removeItem(at: heartbeatsDirectoryURL)
} catch CocoaError.fileNoSuchFile {
// Do nothing.
} catch {
throw error
}
#endif // os(tvOS)
}
}

#endif // ENABLE_FIREBASE_CORE_INTERNAL_TESTING_UTILS
1 change: 0 additions & 1 deletion FirebaseCore/Internal/Tests/Common/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import XCTest
@testable import FirebaseCoreInternal
import HeartbeatLoggingTestUtils

// MARK: - Assertions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import XCTest
@testable import FirebaseCoreInternal
import HeartbeatLoggingTestUtils

class HeartbeatLoggingIntegrationTests: XCTestCase {
// 2021-11-01 @ 00:00:00 (EST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import XCTest
@testable import FirebaseCoreInternal
import HeartbeatLoggingTestUtils

class HeartbeatControllerTests: XCTestCase {
// 2021-11-01 @ 00:00:00 (EST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import XCTest
@testable import FirebaseCoreInternal
import HeartbeatLoggingTestUtils

class HeartbeatsBundleTests: XCTestCase {
// 2021-11-01 @ 00:00:00 (EST)
Expand Down
Loading

0 comments on commit 1e04018

Please sign in to comment.