Skip to content

Commit e789676

Browse files
authored
Build and run Functions Combine Unit Tests from SPM (#8080)
1 parent 0c7d16e commit e789676

File tree

10 files changed

+213
-8
lines changed

10 files changed

+213
-8
lines changed

.github/workflows/functions.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ on:
77
- '.github/workflows/functions.yml'
88
- 'Interop/Auth/Public/*.h'
99
- 'FirebaseMessaging/Sources/Interop/*.h'
10+
- 'FirebaseTestingSupport/Functions/**'
11+
- 'FirebaseCombineSwift/Sources/Functions/**'
1012
- 'Gemfile*'
13+
1114
schedule:
1215
# Run every day at 3am (PST) - cron uses UTC times
1316
- cron: '0 11 * * *'
@@ -43,6 +46,8 @@ jobs:
4346
run: xcodebuild -list
4447
- name: iOS Unit Tests
4548
run: scripts/third_party/travis/retry.sh ./scripts/build.sh FirebaseFunctions iOS spmbuildonly
49+
- name: Combine Unit Tests
50+
run: scripts/third_party/travis/retry.sh ./scripts/build.sh FunctionsCombineUnit iOS spm
4651

4752
spm-cron:
4853
# Don't run on private repo.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1250"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
</BuildAction>
9+
<TestAction
10+
buildConfiguration = "Debug"
11+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
shouldUseLaunchSchemeArgsEnv = "YES">
14+
<Testables>
15+
<TestableReference
16+
skipped = "NO">
17+
<BuildableReference
18+
BuildableIdentifier = "primary"
19+
BlueprintIdentifier = "FunctionsCombineUnit"
20+
BuildableName = "FunctionsCombineUnit"
21+
BlueprintName = "FunctionsCombineUnit"
22+
ReferencedContainer = "container:">
23+
</BuildableReference>
24+
</TestableReference>
25+
</Testables>
26+
</TestAction>
27+
<LaunchAction
28+
buildConfiguration = "Debug"
29+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
30+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
31+
launchStyle = "0"
32+
useCustomWorkingDirectory = "NO"
33+
ignoresPersistentStateOnLaunch = "NO"
34+
debugDocumentVersioning = "YES"
35+
debugServiceExtension = "internal"
36+
allowLocationSimulation = "YES">
37+
</LaunchAction>
38+
<ProfileAction
39+
buildConfiguration = "Release"
40+
shouldUseLaunchSchemeArgsEnv = "YES"
41+
savedToolIdentifier = ""
42+
useCustomWorkingDirectory = "NO"
43+
debugDocumentVersioning = "YES">
44+
</ProfileAction>
45+
<AnalyzeAction
46+
buildConfiguration = "Debug">
47+
</AnalyzeAction>
48+
<ArchiveAction
49+
buildConfiguration = "Release"
50+
revealArchiveInOrganizer = "YES">
51+
</ArchiveAction>
52+
</Scheme>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2017 Google
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+
// This file is a copy of Functions/Internal/FIRFunctions+Internal.h except for the modular import
16+
// of FirebaseFunctions.
17+
18+
#import <Foundation/Foundation.h>
19+
20+
@import FirebaseFunctions;
21+
22+
@protocol FIRAppCheckInterop;
23+
@protocol FIRAuthInterop;
24+
@protocol FIRMessagingInterop;
25+
@class FIRHTTPSCallableResult;
26+
27+
NS_ASSUME_NONNULL_BEGIN
28+
29+
@interface FIRFunctions (Testing)
30+
31+
/**
32+
* Calls an http trigger endpoint.
33+
* @param name The name of the http trigger.
34+
* @param data Parameters to pass to the function. Can be anything encodable as JSON.
35+
* @param completion The block to call when the request is complete.
36+
*/
37+
- (void)callFunction:(NSString *)name
38+
withObject:(nullable id)data
39+
timeout:(NSTimeInterval)timeout
40+
completion:(void (^)(FIRHTTPSCallableResult *_Nullable result,
41+
NSError *_Nullable error))completion;
42+
43+
/**
44+
* Constructs the url for an http trigger. This is exposed only for testing.
45+
* @param name The name of the endpoint.
46+
*/
47+
- (NSString *)URLWithName:(NSString *)name;
48+
49+
/**
50+
* Sets the functions client to send requests to localhost instead of Firebase.
51+
* For testing only.
52+
*/
53+
- (void)useLocalhost;
54+
55+
/**
56+
* Internal initializer for the Cloud Functions client.
57+
* @param projectID The project ID for the Firebase project.
58+
* @param region The region for the http trigger, such as "us-central1".
59+
* @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
60+
* @param auth The auth provider to use (optional).
61+
* @param messaging The messaging interop to use (optional).
62+
*/
63+
- (instancetype)initWithProjectID:(NSString *)projectID
64+
region:(NSString *)region
65+
customDomain:(nullable NSString *)customDomain
66+
auth:(nullable id<FIRAuthInterop>)auth
67+
messaging:(nullable id<FIRMessagingInterop>)messaging
68+
appCheck:(nullable id<FIRAppCheckInterop>)appCheck;
69+
70+
@end
71+
72+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2017 Google
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+
// This file is a copy of Functions/Internal/FIRHTTPSCallable+Internal.h except for the modular
16+
// import of FirebaseFunctions.
17+
18+
#import <Foundation/Foundation.h>
19+
20+
@import FirebaseFunctions;
21+
22+
@class FIRFunctions;
23+
24+
NS_ASSUME_NONNULL_BEGIN
25+
26+
@interface FIRHTTPSCallableResult (Testing)
27+
28+
/**
29+
* Initializes a callable result.
30+
*
31+
* @param result The data to wrap.
32+
*/
33+
- (instancetype)initWithData:(id)result;
34+
35+
@end
36+
37+
@interface FIRHTTPSCallable (Testing)
38+
39+
/**
40+
* Initializes a reference to the given http trigger.
41+
*
42+
* @param functionsClient The functions client to use for making network requests.
43+
* @param name The name of the http trigger.
44+
*/
45+
- (instancetype)initWithFunctions:(FIRFunctions *)functionsClient name:(NSString *)name;
46+
47+
@end
48+
49+
NS_ASSUME_NONNULL_END

FirebaseTestingSupport/Functions/Sources/Public/FirebaseFunctionsTestingSupport/FIRHTTPSCallableFake.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import <FirebaseFunctions/FIRHTTPSCallable.h>
1615
#import <Foundation/Foundation.h>
1716

17+
#import <FirebaseFunctions/FIRHTTPSCallable.h>
18+
1819
NS_ASSUME_NONNULL_BEGIN
1920

2021
/// A fake object to replace a real `FIRHTTPSCallableResult` in tests.

FirebaseCombineSwift/Tests/Unit/Functions/HTTPSCallableTests.swift renamed to Functions/Tests/CombineUnit/HTTPSCallableTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
// limitations under the License.
1414

1515
import Foundation
16+
1617
import Combine
17-
import XCTest
18-
import FirebaseFunctions
18+
import FirebaseFunctionsCombineSwift
1919
@testable import FirebaseFunctionsTestingSupport
20+
import XCTest
2021

2122
// hardcoded in FIRHTTPSCallable.m
2223
private let kFunctionsTimeout: TimeInterval = 70.0
24+
private let expectationTimeout: TimeInterval = 2
2325

2426
class MockFunctions: Functions {
2527
var mockCallFunction: () throws -> HTTPSCallableResult?

Package.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,6 @@ let package = Package(
408408
dependencies: ["FirebaseAuth"],
409409
path: "FirebaseCombineSwift/Sources/Auth"
410410
),
411-
.target(
412-
name: "FirebaseFunctionsCombineSwift",
413-
dependencies: ["FirebaseFunctions"],
414-
path: "FirebaseCombineSwift/Sources/Functions"
415-
),
416411
.target(
417412
name: "FirebaseStorageCombineSwift",
418413
dependencies: [
@@ -643,6 +638,8 @@ let package = Package(
643638
]
644639
),
645640

641+
// MARK: Firebase Functions
642+
646643
.target(
647644
name: "FirebaseFunctionsTarget",
648645
dependencies: [.target(name: "FirebaseFunctions",
@@ -662,6 +659,27 @@ let package = Package(
662659
.headerSearchPath("../../"),
663660
]
664661
),
662+
.target(
663+
name: "FirebaseFunctionsCombineSwift",
664+
dependencies: ["FirebaseFunctions"],
665+
path: "FirebaseCombineSwift/Sources/Functions"
666+
),
667+
.testTarget(
668+
name: "FunctionsCombineUnit",
669+
dependencies: ["FirebaseFunctionsCombineSwift",
670+
"FirebaseFunctionsTestingSupport",
671+
"SharedTestUtilities"],
672+
path: "Functions/Tests/CombineUnit"
673+
),
674+
.target(
675+
name: "FirebaseFunctionsTestingSupport",
676+
dependencies: ["FirebaseFunctions"],
677+
path: "FirebaseTestingSupport/Functions/Sources",
678+
publicHeadersPath: "Public",
679+
cSettings: [
680+
.headerSearchPath("../../.."),
681+
]
682+
),
665683

666684
.target(
667685
name: "FirebaseInAppMessagingTarget",

scripts/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,12 @@ case "$product-$platform-$method" in
646646
test
647647
;;
648648

649+
# Note that the combine tests require setting the minimum iOS version to 13.0
649650
*-*-spm)
650651
RunXcodebuild \
651652
-scheme $product \
652653
"${xcb_flags[@]}" \
654+
IPHONEOS_DEPLOYMENT_TARGET=13.0 \
653655
test
654656
;;
655657

scripts/check_imports.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ private func checkFile(_ file: String, logger: ErrorLogger, inRepo repoURL: URL)
104104
inSwiftPackageElse = false
105105
} else if inSwiftPackage {
106106
continue
107+
} else if file.contains("FirebaseTestingSupport") {
108+
// Module imports ok in SPM only test infrastructure.
109+
continue
107110
} else if line.starts(with: "@import") {
108111
// "@import" is only allowed for Swift Package Manager.
109112
logger.importLog("@import should not be used in CocoaPods library code", file, lineNum)

scripts/check_no_module_imports.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ git grep "${options[@]}" \
3434
':(exclude,glob)Crashlytics/**' \
3535
':(exclude,glob)FirebaseStorage/**' \
3636
':(exclude,glob)SwiftPMTests/**' \
37+
':(exclude,glob)FirebaseTestingSupport/**' \
3738
':(exclude)Functions/FirebaseFunctions/FIRFunctions.m' \
3839
':(exclude)HeadersImports.md' && exit_with_error
3940

0 commit comments

Comments
 (0)