Skip to content

Commit d823614

Browse files
authored
Initial RC Swift API tests (#5602)
1 parent 755410f commit d823614

File tree

7 files changed

+203
-23
lines changed

7 files changed

+203
-23
lines changed

.github/workflows/remoteconfig.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,50 @@ on:
1515

1616
jobs:
1717

18+
remoteconfig:
19+
env:
20+
plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
21+
runs-on: macos-latest
22+
strategy:
23+
matrix:
24+
target: [iOS, tvOS, macOS]
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Setup Bundler
28+
run: scripts/setup_bundler.sh
29+
- name: Install Secret GoogleService-Info.plist
30+
run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/RemoteConfigSwiftAPI/GoogleService-Info.plist.gpg \
31+
FirebaseRemoteConfig/Tests/SwiftAPI/GoogleService-Info.plist "$plist_secret"
32+
- name: BuildAndUnitTest # can be replaced with pod lib lint with CocoaPods 1.10
33+
run: scripts/third_party/travis/retry.sh scripts/build.sh RemoteConfig ${{ matrix.target }} unit
34+
- name: IntegrationTest
35+
if: matrix.target == 'iOS'
36+
run: ([ -z $plist_secret ] || scripts/third_party/travis/retry.sh scripts/build.sh RemoteConfig iOS integration)
37+
38+
pod-lib-lint:
39+
runs-on: macOS-latest
40+
41+
strategy:
42+
matrix:
43+
target: [ios, tvos, macos]
44+
steps:
45+
- uses: actions/checkout@v2
46+
- name: Setup Bundler
47+
run: scripts/setup_bundler.sh
48+
- name: Build and test
49+
run: |
50+
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --skip-tests --platforms=${{ matrix.target }}
51+
52+
catalyst:
53+
runs-on: macOS-latest
54+
steps:
55+
- uses: actions/checkout@v2
56+
- name: Setup Bundler
57+
run: scripts/setup_bundler.sh
58+
- name: Setup project and Build for Catalyst
59+
# Only build the unit tests on Catalyst. Test stopped working when GHA moved to Xcode 11.4.1.
60+
run: scripts/test_catalyst.sh FirebaseRemoteConfig build FirebaseRemoteConfig-Unit-unit
61+
1862
quickstart:
1963
env:
2064
plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
@@ -35,3 +79,21 @@ jobs:
3579
- name: Test swift quickstart
3680
run: ([ -z $plist_secret ] || scripts/third_party/travis/retry.sh scripts/test_quickstart.sh Config swift)
3781

82+
remoteconfig-cron-only:
83+
runs-on: macos-latest
84+
if: github.event_name == 'schedule'
85+
strategy:
86+
matrix:
87+
target: [ios, tvos, macos]
88+
flags: [
89+
'--skip-tests --use-modular-headers',
90+
'--skip-tests --use-libraries'
91+
]
92+
needs: pod-lib-lint
93+
steps:
94+
- uses: actions/checkout@v2
95+
- name: Setup Bundler
96+
run: scripts/setup_bundler.sh
97+
- name: PodLibLint RemoteConfig Cron
98+
run: |
99+
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --platforms=${{ matrix.target }} ${{ matrix.flags }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ FirebaseAuth/Tests/Sample/SwiftApiTests/Credentials.swift
88

99
Example/Database/App/GoogleService-Info.plist
1010

11+
FirebaseRemoteConfig/Tests/SwiftAPI/Resources/GoogleService-Info.plist
12+
1113
# FirebaseStorage integration tests GoogleService-Info.plist
1214
FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist
1315

.travis.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -189,36 +189,13 @@ jobs:
189189
- travis_retry ./scripts/pod_lib_lint.rb FirebaseMessaging.podspec --platforms=tvos --use-modular-headers
190190
- travis_retry ./scripts/pod_lib_lint.rb FirebaseMessaging.podspec --platforms=macos --use-modular-headers
191191

192-
- stage: test
193-
env:
194-
- PROJECT=RemoteConfig METHOD=pod-lib-lint QUICKSTART=Config
195-
before_install:
196-
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
197-
script:
198-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --platforms=ios
199-
- travis_retry ./scripts/if_changed.sh ./scripts/test_quickstart.sh Config
200-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --platforms=tvos
201-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --platforms=macos
202-
203192
- stage: test
204193
osx_image: xcode10.3
205194
env:
206195
- PROJECT=RemoteConfig METHOD=pod-lib-lint
207196
script:
208197
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --platforms=ios
209198

210-
- stage: test
211-
if: type = cron
212-
env:
213-
- PROJECT=RemoteConfigCron METHOD=pod-lib-lint
214-
script:
215-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-libraries --platforms=ios
216-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-libraries --platforms=tvos
217-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-libraries --platforms=macos
218-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-modular-headers --platforms=ios
219-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-modular-headers --platforms=tvos
220-
- travis_retry ./scripts/pod_lib_lint.rb FirebaseRemoteConfig.podspec --use-modular-headers --platforms=macos
221-
222199
- stage: test
223200
osx_image: xcode10.3
224201
env:

FirebaseRemoteConfig.podspec

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ app update.
7171
unit_tests.dependency 'OCMock'
7272
unit_tests.requires_arc = true
7373
end
74+
75+
s.test_spec 'swift-api' do |swift_api_tests|
76+
swift_api_tests.platforms = {:ios => '8.0', :osx => '10.11', :tvos => '10.0'}
77+
swift_api_tests.source_files = 'FirebaseRemoteConfig/Tests/SwiftAPI/*.swift'
78+
swift_api_tests.requires_app_host = true
79+
swift_api_tests.resources =
80+
'FirebaseRemoteConfig/Tests/SwiftAPI/GoogleService-Info.plist'
81+
end
7482
end
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2020 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+
import FirebaseCore
16+
import FirebaseRemoteConfig
17+
import XCTest
18+
19+
class APITests: XCTestCase {
20+
var app: FirebaseApp!
21+
var config: RemoteConfig!
22+
23+
override class func setUp() {
24+
FirebaseApp.configure()
25+
}
26+
27+
override func setUp() {
28+
super.setUp()
29+
app = FirebaseApp.app()
30+
config = RemoteConfig.remoteConfig(app: app!)
31+
let settings = RemoteConfigSettings()
32+
settings.minimumFetchInterval = 0
33+
config.configSettings = settings
34+
35+
FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.debug)
36+
}
37+
38+
override func tearDown() {
39+
app = nil
40+
config = nil
41+
super.tearDown()
42+
}
43+
44+
func testFetchThenActivate() {
45+
let expectation = self.expectation(description: #function)
46+
config.fetch { status, error in
47+
if let error = error {
48+
XCTFail("Fetch Error \(error)")
49+
}
50+
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
51+
self.config.activate { error in
52+
if let error = error {
53+
// This API returns an error if the config was unchanged.
54+
//
55+
print("Activate Error \(error)")
56+
}
57+
XCTAssertEqual(self.config["Key1"].stringValue, "Value1")
58+
expectation.fulfill()
59+
}
60+
}
61+
waitForExpectations()
62+
}
63+
64+
func testFetchWithExpirationThenActivate() {
65+
let expectation = self.expectation(description: #function)
66+
config.fetch(withExpirationDuration: 0) { status, error in
67+
if let error = error {
68+
XCTFail("Fetch Error \(error)")
69+
}
70+
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
71+
self.config.activate { error in
72+
if let error = error {
73+
// This API returns an error if the config was unchanged.
74+
//
75+
print("Activate Error \(error)")
76+
}
77+
XCTAssertEqual(self.config["Key1"].stringValue, "Value1")
78+
expectation.fulfill()
79+
}
80+
}
81+
waitForExpectations()
82+
}
83+
84+
func testFetchAndActivate() {
85+
let expectation = self.expectation(description: #function)
86+
config.fetchAndActivate { status, error in
87+
if let error = error {
88+
XCTFail("Fetch and Activate Error \(error)")
89+
}
90+
XCTAssertEqual(self.config["Key1"].stringValue, "Value1")
91+
expectation.fulfill()
92+
}
93+
waitForExpectations()
94+
}
95+
96+
private func waitForExpectations() {
97+
let kFIRStorageIntegrationTestTimeout = 10.0
98+
waitForExpectations(timeout: kFIRStorageIntegrationTestTimeout,
99+
handler: { (error) -> Void in
100+
if let error = error {
101+
print(error)
102+
}
103+
})
104+
}
105+
}

scripts/build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ product can be one of:
3535
InAppMessaging
3636
Messaging
3737
MessagingSample
38+
RemoteConfig
3839
Storage
3940
StorageSwift
4041
SymbolCollision
@@ -50,6 +51,8 @@ platform can be one of:
5051
method can be one of:
5152
xcodebuild (default)
5253
cmake
54+
unit
55+
integration
5356
5457
Optionally, reads the environment variable SANITIZERS. If set, it is expected to
5558
be a string containing a space-separated list with some of the following
@@ -212,6 +215,7 @@ watchos_flags=(
212215
case "$platform" in
213216
iOS)
214217
xcb_flags=("${ios_flags[@]}")
218+
gen_platform=ios
215219
;;
216220

217221
iPad)
@@ -220,10 +224,12 @@ case "$platform" in
220224

221225
macOS)
222226
xcb_flags=("${macos_flags[@]}")
227+
gen_platform=macos
223228
;;
224229

225230
tvOS)
226231
xcb_flags=("${tvos_flags[@]}")
232+
gen_platform=tvos
227233
;;
228234

229235
watchOS)
@@ -461,6 +467,26 @@ case "$product-$platform-$method" in
461467
test
462468
;;
463469

470+
RemoteConfig-*-unit)
471+
pod_gen FirebaseRemoteConfig.podspec --platforms="${gen_platform}"
472+
RunXcodebuild \
473+
-workspace 'gen/FirebaseRemoteConfig/FirebaseRemoteConfig.xcworkspace' \
474+
-scheme "FirebaseRemoteConfig-Unit-unit" \
475+
"${xcb_flags[@]}" \
476+
build \
477+
test
478+
;;
479+
480+
RemoteConfig-*-integration)
481+
pod_gen FirebaseRemoteConfig.podspec --platforms="${gen_platform}"
482+
RunXcodebuild \
483+
-workspace 'gen/FirebaseRemoteConfig/FirebaseRemoteConfig.xcworkspace' \
484+
-scheme "FirebaseRemoteConfig-Unit-swift-api" \
485+
"${xcb_flags[@]}" \
486+
build \
487+
test
488+
;;
489+
464490
Storage-*-xcodebuild)
465491
pod_gen FirebaseStorage.podspec --platforms=ios
466492
RunXcodebuild \
Binary file not shown.

0 commit comments

Comments
 (0)