-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rollouts] RC interop implementation
- Loading branch information
1 parent
739571a
commit 3fc43c6
Showing
10 changed files
with
294 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023 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. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRemoteConfigInterop) | ||
public protocol RemoteConfigInterop { | ||
func registerRolloutsStateSubscriber(_ subscriber: RolloutsStateSubscriber?, | ||
for namespace: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2023 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. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRolloutAssignment) | ||
public class RolloutAssignment: NSObject { | ||
@objc public var rolloutId: String | ||
@objc public var variantId: String | ||
@objc public var templateVersion: Int64 | ||
@objc public var parameterKey: String | ||
@objc public var parameterValue: String | ||
|
||
public init(rolloutId: String, variantId: String, templateVersion: Int64, parameterKey: String, | ||
parameterValue: String) { | ||
self.rolloutId = rolloutId | ||
self.variantId = variantId | ||
self.templateVersion = templateVersion | ||
self.parameterKey = parameterKey | ||
self.parameterValue = parameterValue | ||
super.init() | ||
} | ||
} | ||
|
||
@objc(FIRRolloutsState) | ||
public class RolloutsState: NSObject { | ||
@objc public var assignments: Set<RolloutAssignment> = Set() | ||
|
||
public init(assignmentList: [RolloutAssignment]) { | ||
for assignment in assignmentList { | ||
assignments.insert(assignment) | ||
} | ||
super.init() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
FirebaseRemoteConfig/Interop/RolloutsStateSubscriber.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2023 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. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRolloutsStateSubscriber) | ||
public protocol RolloutsStateSubscriber { | ||
func rolloutsStateDidChange(_ rolloutsState: RolloutsState) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
FirebaseRemoteConfig/Tests/SwiftUnit/RemoteConfigInteropTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2023 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. | ||
|
||
import FirebaseRemoteConfigInterop | ||
import XCTest | ||
|
||
class MockRCInterop: RemoteConfigInterop { | ||
weak var subscriber: FirebaseRemoteConfigInterop.RolloutsStateSubscriber? | ||
func registerRolloutsStateSubscriber(_ subscriber: FirebaseRemoteConfigInterop | ||
.RolloutsStateSubscriber?, | ||
for namespace: String) { | ||
self.subscriber = subscriber | ||
} | ||
} | ||
|
||
class MockRolloutSubscriber: RolloutsStateSubscriber { | ||
var isSubscriberCalled = false | ||
var rolloutsState: RolloutsState? | ||
func rolloutsStateDidChange(_ rolloutsState: FirebaseRemoteConfigInterop.RolloutsState) { | ||
isSubscriberCalled = true | ||
self.rolloutsState = rolloutsState | ||
} | ||
} | ||
|
||
final class RemoteConfigInteropTests: XCTestCase { | ||
let rollouts: RolloutsState = { | ||
let assignment1 = RolloutAssignment( | ||
rolloutId: "rollout_1", | ||
variantId: "control", | ||
templateVersion: 1, | ||
parameterKey: "my_feature", | ||
parameterValue: "false" | ||
) | ||
let assignment2 = RolloutAssignment( | ||
rolloutId: "rollout_2", | ||
variantId: "enabled", | ||
templateVersion: 123, | ||
parameterKey: "themis_big_feature", | ||
parameterValue: "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" | ||
) | ||
let rollouts = RolloutsState(assignmentList: [assignment1, assignment2]) | ||
return rollouts | ||
}() | ||
|
||
func testRemoteConfigIntegration() throws { | ||
let rcSubscriber = MockRolloutSubscriber() | ||
let rcInterop = MockRCInterop() | ||
rcInterop.registerRolloutsStateSubscriber(rcSubscriber, for: "namespace") | ||
rcInterop.subscriber?.rolloutsStateDidChange(rollouts) | ||
|
||
XCTAssertTrue(rcSubscriber.isSubscriberCalled) | ||
XCTAssertEqual(rcSubscriber.rolloutsState?.assignments.count, 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'FirebaseRemoteConfigInterop' | ||
s.version = '10.19.0' | ||
s.summary = 'Interfaces that allow other Firebase SDKs to use Remote Config functionality.' | ||
|
||
s.description = <<-DESC | ||
Not for public use. | ||
A set of protocols that other Firebase SDKs can use to interoperate with FirebaseRemoetConfig in a safe | ||
and reliable manner. | ||
DESC | ||
|
||
s.homepage = 'https://firebase.google.com' | ||
s.license = { :type => 'Apache-2.0', :file => 'LICENSE' } | ||
s.authors = 'Google, Inc.' | ||
|
||
# NOTE that these should not be used externally, this is for Firebase pods to depend on each | ||
# other. | ||
s.source = { | ||
:git => 'https://github.com/firebase/firebase-ios-sdk.git', | ||
:tag => 'CocoaPods-' + s.version.to_s | ||
} | ||
s.social_media_url = 'https://twitter.com/Firebase' | ||
s.ios.deployment_target = '11.0' | ||
s.osx.deployment_target = '10.13' | ||
s.tvos.deployment_target = '12.0' | ||
s.watchos.deployment_target = '6.0' | ||
|
||
s.source_files = 'FirebaseRemoteConfig/Interop/*.swift' | ||
end |
Oops, something went wrong.