-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Semantic Versioning implementation #289
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
80d1d25
feat: added semver support to our existing matchers
pawels-optimizely 2981c20
fix linters
pawels-optimizely ad65d4b
fix linters
pawels-optimizely cf66c93
added more changes
pawels-optimizely a044757
added semver for registry pattern
pawels-optimizely 068ac3d
consolidate all the semver code
pawels-optimizely e3d7150
added ge and le evaluators
pawels-optimizely de95b6a
simplify tests
pawels-optimizely e89d07d
Update pkg/decision/evaluator/matchers/semver_test.go
pawels-optimizely 5cafc5a
cleaning up
pawels-optimizely 89b9406
addressing nit comments
pawels-optimizely e272112
addressing PR comments
pawels-optimizely a91371e
increase coverage
pawels-optimizely ff5136d
increase coverage
pawels-optimizely 18361fd
corrected tests
pawels-optimizely ae97a2d
increased coverage
pawels-optimizely 9a9ca1b
increase coverage
pawels-optimizely be1e4a5
small improvement in the coverage
pawels-optimizely 8eaadb8
add a few more tests and fix split when not build or release
thomaszurkan-optimizely 7849cae
Merge branch 'master' into pawel/semver
thomaszurkan-optimizely ef25dcd
fix merge errors
thomaszurkan-optimizely 57bebb1
slight refactor for lint
thomaszurkan-optimizely a1ba38b
fixing after a refactor right in the middle of doing this pr.
thomaszurkan-optimizely f4c2f88
Merge branch 'master' into pawel/semver
thomaszurkan-optimizely 64ae09c
fix lint error
thomaszurkan-optimizely d2f1ba5
Merge branch 'pawel/semver' of https://github.com/optimizely/go-sdk i…
thomaszurkan-optimizely 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2020, Optimizely, Inc. and contributors * | ||
| * * | ||
| * 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 matchers // | ||
| package matchers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/optimizely/go-sdk/pkg/logging" | ||
|
|
||
| "github.com/optimizely/go-sdk/pkg/decision/evaluator/matchers/utils" | ||
| "github.com/optimizely/go-sdk/pkg/entities" | ||
| ) | ||
|
|
||
| // GeMatcher matches against the "ge" match type | ||
| func GeMatcher(condition entities.Condition, user entities.UserContext, logger logging.OptimizelyLogProducer) (bool, error) { | ||
|
|
||
| if floatValue, ok := utils.ToFloat(condition.Value); ok { | ||
| attributeValue, err := user.GetFloatAttribute(condition.Name) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return floatValue <= attributeValue, nil | ||
| } | ||
|
|
||
| return false, fmt.Errorf("audience condition %s evaluated to NULL because the condition value type is not supported", condition.Name) | ||
| } |
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,162 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2020, Optimizely, Inc. and contributors * | ||
| * * | ||
| * 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 matchers | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/optimizely/go-sdk/pkg/entities" | ||
| ) | ||
|
|
||
| var geMatcher, _ = Get(GeMatchType) | ||
|
|
||
| func TestGeMatcherInt(t *testing.T) { | ||
| condition := entities.Condition{ | ||
| Match: "ge", | ||
| Value: 42, | ||
| Name: "int_42", | ||
| } | ||
|
|
||
| // Test match - same type | ||
| user := entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_42": 43, | ||
| }, | ||
| } | ||
| result, err := geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test match int to float | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_42": 42.9999, | ||
| }, | ||
| } | ||
|
|
||
| result, err = geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test match: 42.9999 converts to 42 | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_42": 42.00000, | ||
| }, | ||
| } | ||
|
|
||
| result, err = geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test no match | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_42": 41, | ||
| }, | ||
| } | ||
|
|
||
| result, err = geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.False(t, result) | ||
|
|
||
| // Test attribute not found | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_43": 42, | ||
| }, | ||
| } | ||
|
|
||
| _, err = geMatcher(condition, user, nil) | ||
| assert.Error(t, err) | ||
|
|
||
| // Test wrong int | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_43": "some_string", | ||
| }, | ||
| } | ||
|
|
||
| _, err = geMatcher(condition, user, nil) | ||
| assert.Error(t, err) | ||
|
|
||
| // Test bad condition | ||
| condition = entities.Condition{ | ||
| Match: "ge", | ||
| Value: "123", | ||
| Name: "int_42", | ||
| } | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "int_43": "some_string", | ||
| }, | ||
| } | ||
|
|
||
| _, err = geMatcher(condition, user, nil) | ||
| assert.Error(t, err) | ||
| } | ||
|
|
||
| func TestGeMatcherFloat(t *testing.T) { | ||
| condition := entities.Condition{ | ||
| Match: "ge", | ||
| Value: 4.2, | ||
| Name: "float_4_2", | ||
| } | ||
|
|
||
| // Test match float to int | ||
| user := entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "float_4_2": 5, | ||
| }, | ||
| } | ||
| result, err := geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test match | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "float_4_2": 4.29999, | ||
| }, | ||
| } | ||
| result, err = geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test match | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "float_4_2": 4.2, | ||
| }, | ||
| } | ||
|
|
||
| result, err = geMatcher(condition, user, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, result) | ||
|
|
||
| // Test attribute not found | ||
| user = entities.UserContext{ | ||
| Attributes: map[string]interface{}{ | ||
| "float_4_3": 4.2, | ||
| }, | ||
| } | ||
|
|
||
| _, err = geMatcher(condition, user, nil) | ||
| assert.Error(t, err) | ||
| } | ||
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,40 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2020, Optimizely, Inc. and contributors * | ||
| * * | ||
| * 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 matchers // | ||
| package matchers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/optimizely/go-sdk/pkg/logging" | ||
|
|
||
| "github.com/optimizely/go-sdk/pkg/decision/evaluator/matchers/utils" | ||
| "github.com/optimizely/go-sdk/pkg/entities" | ||
| ) | ||
|
|
||
| // LeMatcher matches against the "le" match type | ||
| func LeMatcher(condition entities.Condition, user entities.UserContext, logger logging.OptimizelyLogProducer) (bool, error) { | ||
|
|
||
| if floatValue, ok := utils.ToFloat(condition.Value); ok { | ||
| attributeValue, err := user.GetFloatAttribute(condition.Name) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return floatValue >= attributeValue, nil | ||
| } | ||
|
|
||
| return false, fmt.Errorf("audience condition %s evaluated to NULL because the condition value type is not supported", condition.Name) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.