Repository navigation
feat: upgrade OpenFeature SDK to 0.9.0 #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicklasl
wants to merge
3
commits into
main
Choose a base branch
from
nicklasl/openfeature-0.9.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package com.spotify.confidence.openfeature | |
| import com.spotify.confidence.ConfidenceValue | ||
| import dev.openfeature.kotlin.sdk.EvaluationContext | ||
| import dev.openfeature.kotlin.sdk.TrackingEventDetails | ||
| import dev.openfeature.kotlin.sdk.exceptions.OpenFeatureError | ||
|
|
||
| internal fun mergeEventContext( | ||
| sessionContext: Map<String, ConfidenceValue>, | ||
|
|
@@ -37,12 +38,16 @@ internal fun TrackingEventDetails?.toTrackingData(): Map<String, ConfidenceValue | |
| ) + structure.asMap().mapValues { it.value.toConfidenceValue() } | ||
| } | ||
|
|
||
| private fun Number.toConfidenceValue(): ConfidenceValue = when (this) { | ||
| private const val MAX_EXACT_DOUBLE_INTEGER = 9_007_199_254_740_992L | ||
|
|
||
| internal fun Number.toConfidenceValue(): ConfidenceValue = when (this) { | ||
| is Int -> ConfidenceValue.Integer(this) | ||
| is Long -> if (this in Int.MIN_VALUE..Int.MAX_VALUE) { | ||
| ConfidenceValue.Integer(toInt()) | ||
| } else { | ||
| } else if (this in -MAX_EXACT_DOUBLE_INTEGER..MAX_EXACT_DOUBLE_INTEGER) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be like int, |
||
| ConfidenceValue.Double(toDouble()) | ||
| } else { | ||
| throw OpenFeatureError.ParseError("Long value cannot be represented exactly by Confidence") | ||
| } | ||
| is Double -> ConfidenceValue.Double(this) | ||
| is Float -> ConfidenceValue.Double(toDouble()) | ||
|
|
||
69 changes: 69 additions & 0 deletions
69
...r/src/test/java/com/spotify/confidence/openfeature/ConfidenceFeatureProviderObjectTest.kt
This file contains hidden or 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,69 @@ | ||
| package com.spotify.confidence.openfeature | ||
|
|
||
| import com.spotify.confidence.Confidence | ||
| import com.spotify.confidence.ConfidenceValue | ||
| import com.spotify.confidence.FlagResolution | ||
| import com.spotify.confidence.ResolveReason | ||
| import com.spotify.confidence.client.ResolvedFlag | ||
| import com.spotify.confidence.getEvaluation | ||
| import dev.openfeature.kotlin.sdk.Reason | ||
| import dev.openfeature.kotlin.sdk.Value | ||
| import dev.openfeature.kotlin.sdk.exceptions.ErrorCode | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Assert.assertSame | ||
| import org.junit.Test | ||
|
|
||
| class ConfidenceFeatureProviderObjectTest { | ||
| @Test | ||
| fun missingFlagPreservesLongDefaults() { | ||
| val provider = createProvider(FlagResolution.EMPTY) | ||
|
|
||
| for (count in listOf(42L, Long.MAX_VALUE)) { | ||
| val default = Value.Structure(mapOf("count" to Value.Long(count))) | ||
|
|
||
| val evaluation = provider.getObjectEvaluation("missing", default, null) | ||
|
|
||
| assertSame(default, evaluation.value) | ||
| assertEquals(Reason.ERROR.name, evaluation.reason) | ||
| assertEquals(ErrorCode.FLAG_NOT_FOUND, evaluation.errorCode) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun matchingFlagResolvesWithLongMaxValueInUnusedDefault() { | ||
| val provider = createProvider( | ||
| FlagResolution( | ||
| context = emptyMap(), | ||
| flags = listOf( | ||
| ResolvedFlag( | ||
| flag = "size", | ||
| variant = "variant-1", | ||
| value = mapOf("count" to ConfidenceValue.Integer(42)), | ||
| reason = ResolveReason.RESOLVE_REASON_MATCH, | ||
| shouldApply = false | ||
| ) | ||
| ), | ||
| resolveToken = "token" | ||
| ) | ||
| ) | ||
| val default = Value.Structure(mapOf("count" to Value.Long(Long.MAX_VALUE))) | ||
|
|
||
| val evaluation = provider.getObjectEvaluation("size", default, null) | ||
|
|
||
| assertEquals(Value.Structure(mapOf("count" to Value.Integer(42))), evaluation.value) | ||
| assertEquals(Reason.TARGETING_MATCH.name, evaluation.reason) | ||
| assertEquals("variant-1", evaluation.variant) | ||
| assertNull(evaluation.errorCode) | ||
| } | ||
|
|
||
| private fun createProvider(resolution: FlagResolution): ConfidenceFeatureProvider { | ||
| val confidence = mockk<Confidence>(relaxed = true) | ||
| every { confidence.getFlag<Any>(any(), any()) } answers { | ||
| resolution.getEvaluation(firstArg(), secondArg<Any>(), emptyMap()) | ||
| } | ||
| return ConfidenceFeatureProvider.create(confidence) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not double.max?