[FeatureFlag] add more tests
This commit is contained in:
parent
df29b1dd8e
commit
991c7ff7f0
9 changed files with 161 additions and 18 deletions
|
|
@ -17,7 +17,6 @@
|
|||
package io.element.android.libraries.featureflag.api
|
||||
|
||||
interface FeatureFlagService {
|
||||
|
||||
/**
|
||||
* @param feature the feature to check for
|
||||
*
|
||||
|
|
|
|||
|
|
@ -20,36 +20,29 @@ import com.squareup.anvil.annotations.ContributesTo
|
|||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.ElementsIntoSet
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.featureflag.impl.BuildtimeFeatureFlagProvider
|
||||
import io.element.android.libraries.featureflag.impl.FeatureFlagProvider
|
||||
import io.element.android.libraries.featureflag.impl.PreferencesFeatureFlagProvider
|
||||
import io.element.android.libraries.featureflag.impl.RuntimeFeatureFlagProvider
|
||||
|
||||
@Module
|
||||
@ContributesTo(AppScope::class)
|
||||
object FeatureFlagModule {
|
||||
|
||||
@Provides
|
||||
fun providesRuntimeFeatureFlagProvider(preferencesFeatureFlagProvider: PreferencesFeatureFlagProvider): RuntimeFeatureFlagProvider {
|
||||
return preferencesFeatureFlagProvider
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@ElementsIntoSet
|
||||
fun providesFeatureFlagProvider(
|
||||
buildMeta: BuildMeta,
|
||||
buildType: BuildType,
|
||||
runtimeFeatureFlagProvider: PreferencesFeatureFlagProvider,
|
||||
buildtimeFeatureFlagProvider: BuildtimeFeatureFlagProvider,
|
||||
runtimeFeatureFlagProvider: RuntimeFeatureFlagProvider,
|
||||
): Set<FeatureFlagProvider> {
|
||||
val providers = HashSet<FeatureFlagProvider>()
|
||||
//TODO change this condition?
|
||||
if (buildMeta.isDebug) {
|
||||
providers.add(runtimeFeatureFlagProvider)
|
||||
} else {
|
||||
if (buildType == BuildType.RELEASE) {
|
||||
providers.add(buildtimeFeatureFlagProvider)
|
||||
} else {
|
||||
providers.add(runtimeFeatureFlagProvider)
|
||||
}
|
||||
return providers
|
||||
}
|
||||
|
|
|
|||
27
libraries/featureflag/test/build.gradle.kts
Normal file
27
libraries/featureflag/test/build.gradle.kts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("io.element.android-library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.libraries.featureflag.test"
|
||||
|
||||
dependencies {
|
||||
api(projects.libraries.featureflag.api)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.featureflag.test
|
||||
|
||||
import io.element.android.libraries.featureflag.api.Feature
|
||||
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||
|
||||
class FakeFeatureFlagService(
|
||||
initialState: Map<String, Boolean> = emptyMap()
|
||||
) : FeatureFlagService {
|
||||
|
||||
private val enabledFeatures = HashMap(initialState)
|
||||
|
||||
override suspend fun setFeatureEnabled(feature: Feature, enabled: Boolean): Boolean {
|
||||
enabledFeatures[feature.key] = enabled
|
||||
return true
|
||||
}
|
||||
|
||||
override suspend fun isFeatureEnabled(feature: Feature): Boolean {
|
||||
return enabledFeatures[feature.key] ?: feature.defaultValue
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue